I think its a basic human right to be able to use the toilet when you need to. Only the person that needs the toilet, knows how urgently they need to go, so how could anyone else judge if they deserve "permission" or have to wait?
My high school had 8 classes of roughly 30 per year group, and only one set of toilets. Those toilets were locked, and only unlocked at breaktime, and lunch. But the teachers would stop in and have their break first, so despite a 15 minute break, the toilets were only open for the last 7 or so, and they would be shouting trying to rush everyone to get locked back up and back to their room before the bell went, it was chaos. Several of the cubicles were out of order on any given day, meaning only about 6 were useable, and one solitary toilet roll was passed round the room. Same at lunch, only unlocked for the last 10n minutes but you weren't even allowed out of the canteen or into the building (auto lock doors) til 5 minutes to end.
If you needed the loo during lesson, if you managed to get permission, you had to go to the office, find out which teacher had the key that day. Then trek to their room, interrupt their lesson to get the key, go to the toilets, lock up, back to drop key then back to your own class. Probably get strays who were wagging class wander in you couldn't get rid of too. You'd lose at least 15 minutes doing all that, but apparently it had to be that way as pupils would trash them during lessons if they were open.
I have no doubt the cubicles not in use were deliberate damage, ripped off seats and doors. But to punish everyone by them being locked and not accessible between classes at all wasn't okay either. I don't know what the solution should have been, but what it was, gave me severe anxiety, that i felt desperate for a wee in the run up to break and could barely pass anything. I've had a lifelong fear of lack of access to a toilet since.