The simplest answer is because the toilet is always the dirtiest place in the house, and several scientific studies point to the fact of microparticles of faeces being able to be transported by water droplets after flushing the toilet. These in some extreme cases can even be found in toothbrushes... so separating the "*******" of everything else i the bathroom is a pretty damn good idea.
What strikes me odd is that doors in bathrooms need to open to the outside "by law"... almost no country I know does that...
By law? I think it's just because these are small rooms and with doors opening "to inside" it would be much less comfortable.
To prevent the water droplets with germs from spreading around the bathroom while flushing the toilet, you can just close the seat with its cover. There is no need to have a door for that.
By the way, it's in fact difficult not to transport germs to different places after using the toilet. Touching the door handle is here not such a problem as touching the water tap while washing hands. You have used the toilet. And now you have to touch the tap to open the water. With your hand with germs. The germs are transferred to the tap. You have washed your hands - and now you need to close the water. You have to touch the tap with germs to do it. In hospital for surgeons they have special taps that can be opened and closed using the arm instead of the palm - but in case of the taps met in private hauses it's either difficult (in case of modern taps, these which you push up to open the water and down to close it) or impossible (in case of the old-type ones, where you have to turn a valve). And it's exaggerating anyway. Imagine that you come back home from outside. You have touched money, you have touched a handrail in a bus, maybe also a handrail in the stairs while walking upstairs to your apartment. Everything full of germs, maybe even more full than the toilet. And what do you do? First you touch the handle to the main door of your apartment. Then you touch handles of different doors in your apartment. For sure the handle of the main bathroom part (with the washing basin), because you had to do it just to be able to wash your hands. You have germs even on the main bathroom door handle anyway.
I think it's enough to avoid touching things like door handles or bathroom taps before eating, after you wash your hands (although it's difficult since the handle of the bathroom door also has germs, you may wash your hands in the kitchen sink, but you don't have soap there, and washing hands using washing-up liquid is not good for your skin). Everything beyond that is just exaggerating.
By the way, I haven't really met what you are describing (separate room with the toilet within the bathroom) in private houses and apartments in Poland. If so, then there is a totally separate room for the bathroom, and a totally separate room for the toilet. Usually also having a sink, and the separate bathroom also having a toilet "throne". And the purpose of that is as has been already explained. One person is having a bath, which can sometimes even 2 hours or longer, if someone likes to relax having a bath, in this time another person can use the toilet or wash the hands. In some apartment blocks from the 1970's I have met also a cheaper version of that, in case of which there is only a toilet bowl in the toilet room, there is no sink. And there is no toilet in the bathroom. To wash your hands you have to go out and enter the bathroom. This makes less sense, but still, when the bathroom is busy, and you use the toilet in a separate room, you can always wash your hands in the kitchen.
In older apartment blocks, from shortly after the World War 2, I have met an even more primitive solution. There is a bathroom with a toilet and a bath (equipped with a coal water heater - yes, you have to make a fire in it to have a bath) only, without any sink - a sink is only in the kitchen. And this sink doesn't have hot water at all.