How would I prevent it? This is very easy. We do it here in the US and it works quite well.
We have a teacher, and we have a teacher assistant/aid. Sometimes it's a professional hire, sometimes it's a parent volunteer. Both watch and help out the children. They also close the doors during class time. But then, I suppose we have better guidelines here with child to adult ratio (here it's 1:10, and classrooms aren't much bigger than 20, 25 max). A kindergarten class with only one adult in the room is unheard of here, even the older grades have parent volunteers to come in and help out with the class. Imagine... with all the stay at home moms, one could come in to volunteer. Or the school could hire another aid for the younger classrooms. I don't understand why no one has thought of it before over there?
It really is sad when a first world country is further behind us when we have consistently gotten appallingly low test scores across the board...
In any case, it's not really my responsibility to figure out how a teacher is going to do her job any more than it's my responsibility to figure out how an incompetent contractor is going to properly do the job I hired them to do. I leave that up to the company to fix problems and come up with preventative solutions that work best for them. The teacher now knows that children escaping is a possibility, I expect her to figure out a way to deal with it. Just like I expect a contractor to figure out a way to do their job without ruining my house further.
I've watched large groups of small children as a teen, sometimes without an assistant and at any given time I could account for each and every one of them, and I still was able to coordinate successful step by step activities. I expect a teacher who has gone to school to work with this particular age demographic to be able to do better than an untrained teenager.
The only reason everyone is alright with this is because no one got hurt, and the children were only in the bathroom. There could have been an emergency, there could have been an injury that no one would have known about for a while considering the teacher didn't even find the kids until they came back.