OP go into a large room, undertake several different tasks for a long period of time and try to keep your eye on the door at all times.
You will soon find that it's not possible.
For example, try cooking and looking at the door behind you at the same time.
Teachers cannot physically watch every child, every moment. It's just not possible.
Schools cannot lock children in the class, it's against fire regulations and probably many other guidelines.
So teachers have to teach, amongst all the other teaching, that children have to ask before leaving the room.
If they fail to do that, there is a consequence which will hopefully help to reinforce this simple but important safety rule.
Yes, the teacher is responsible for the child's safety whilst in her care which is why she saw this as a serious matter.
As a parent you absolutely should reinforce this at home so that your dd learns quickly how to help keep herself safe by following the very clearly stated, simple rules which are appropriate to her age.