So what kind of situation would this take place in?
I heard it was like that at colleges where it would.be more likely to happen
dunno if its true though
At Secondary School there's no legality about it at all.
You can't leave, because you have to remain on the school premises for the entire school day. That is the law. To leave is to play truancy. Leaving just the room and wandering around the school will probably get you in trouble with your school rules, which normally dictate that you have to be in a classroom during lessontime.
At non-compulsory education the individual establishment will probably have rules for you.
At my college (high school) it was that you could leave if your lecturer doesn't turn up within 10 minutes of the class starting. This can happen because your teacher isn't always teaching in the same room, and they get distracted elsewhere. We can leave at this point because we're at the college optionally.
The same is true at university, although I think they ask us to wait 15 minutes before we leave.