In some cases it is more convenient and practical to have a light switch not by the entry inside the room but rather outside the room. Bathrooms can be small, crowded, etc. so that it makes sense to put a switch outside the bathroom close to the door opening. You turn the light on, enter the bathroom, exit the bathroom and turn the light off. It may make sense to have the switch inside a bedroom, but because you are not going to sleep in the bathroom, you will open the door to get out and - here you go - a switch to turn the light off.
I believe that NEC does not care if the switch is outside a room/bathroom.
I believe that NEC does not care if the switch is outside a room/bathroom.