Yes, ANC headphones do protect your hearing, but they offer weaker protection than specialized heavy-duty equipment like you'd find on a construction site or a shooting range. When using your AirPods Pro your Apple Watch will even factor that in its noise measurements and show you the original noise level and the one that your ears are actually subject to thanks to ANC. For example if I sit right next to a loud vacuum cleaner my Watch says 85 dB, but when I enable ANC on my AirPods Pro 2 it drops down to 62 dB.
One issue is than ANC can't predict and sometimes react fast enough to sudden loud noises, so if an engine backfires next to you, your ANC headphones will take a few miliseconds to catch up and will allow the original sound (minus their inherent (passive) sound isolation) to reach your ear.