I hate peaking under the stalls or knocking doors to figure it out. The answer is so simple.
The US is cheap. We even famously have large gaps between the door/stall panels. I can only imagine it is to accommodate temperature/humidity changes so that they don’t jam.
Nicer places sometimes have actual deadbolt locks connected to a vacant/occupied indicator on the exterior. But it is rare. Usually it’s just a gapped stall with a sliding lock that will often not even line up correctly without wiggling the door.
In some instances I have had to use my gym key fob in place of the missing sliding mechanism to secure the door.
I can only imagine it is to accommodate temperature/humidity changes so that they don’t jam.
You could deal with that while still keeping privacy with a rabeted edge on the door sides.
It’s to shame you out of doing drugs and having sex in the stalls. It doesn’t work because people who are going to do that in a public toilet are usually immune to said shame.