National building codes can make this law.
In Belgium, your building-permit contains a clause you need approval from the city fire-department. They send a fireman that has to check the safety of your building. If it's a public building, your main exit doors must be opening outwards, for evacuation purposes. But they don't care about the toilet door ...
Interesting fact in the same context: in the case of an emergency, your elevator would not be available and you should use the staircase. It is required by the same set of laws that if you follow the staircase all the way down, you have to end up at the ground floor, not in the basement. This is accomplished most of the time by adding another corner or a door to get to the basement level. Additionally, this door MUST open towards the staircase, so confused, scared people don't accidentally go through this door and end up in the basement.
(The fireman check emergency-sings & lightning, exit-routes, if there are fire extinguisher available in accessible places, ... If they find any violations, you get a grace period to fix things. Your building permit is actually revoked if you don't resolve the issues. I'm not sure what the consequences are actually ?)
One of the previous places I worked, we had a fireman talk us through the emergency procedures for the building at one point, and he recounted how it was relatively common for them to find dead people immediately inside exits that were locked, but where the key was in the door, or that opened the wrong way, or in other situations where anyone would've trivially gotten out in seconds in normal conditions, as a way of illustrating just how confusion and fear or carbon monoxide/lack of oxygen would sometimes make people totally unable to overcome even the most basic obstacles during a fire.