Pay toilets actually used to be pretty common in the US although even I've never encountered one, they started declining by the time the 80s began. One reason was the noted one above, they effectively discriminated against women. However the real reason for them wasn't to generate revenue (which was pretty low regardless) but actually to keep the stalls free of vandalism and clean. The idea was that if you had to pay for the privilege you'd be more respectful and it would keep people out who wanted to go in to cause trouble. But that didn't work because people would often get angry and trash the bathroom out of spite anyway.
Just mentioned this to my mom and she said that when she was little her mom would have her go under the door to unlock it and that it was common to just hold the door open if someone else was right there waiting.