We went through a phase earlier this school year of children destroying the toilets during lessons. I'm talking things like ripping the doors off, unscrewing the locks, shoving things down the toilets to block them, smearing the walls with excrement, etc. We reached a point several times that we almost had to close the entire school because good, innocent children were sobbing buckets because they couldn't go to the toilet at break time due to them all being put out of order during period 1 and 2. Of course we always punish the ones who did it, but that doesn't change the fact that those toilets are now out of order and can't be used by the sweet children who did nothing wrong.
The only way we could stop this was to have a blanket ban on going to the toilet in lessons. We're told to use our discretion but children are very good at pretending to be desperate when they're not, and it's often impossible to discern who is desperate and who isn't.
One time a few months ago I let a girl go who had started her period unexpectedly. Three boys who had been banned by their head of year from going to the toilet in lessons because of their abusive behaviour when they left went absolutely ballistic at me. For a full thirty minutes they screamed abuse at me, they called me a slut, a whore, a c, a b*, and I couldn't reach my lesson because they were screaming so loud without stopping. I sent for on call but on call couldn't come because a girl who had been let out of her lesson to go to the toilet had locked herself into a cubicle and was self harming, so they were trying to break into her cubicle. Then when the boys screaming abuse at me realised it wasn't getting them out, I had to remove the girl (with her consent) because they were abusing the girl instead.
It is so, so easy to judge schools for having toilet bans, but you have no idea what we're dealing with and how fast things can spiral out of control.