I think I understand all the requirements:
The natural action when leaving the bathroom is to turn one of the doorknobs and open the door. For safety reasons this action, without any other required motions, must allow egress from the room under any and all conditions. (Thanks Wolf Harper)
Also, to solve the specified problem, opening the door this way, without any other required motions, must normally (ie. absent failure or emergency) unlock both doors. Requiring additional motions to unlock both doors would obviate the prupose of the project; you might as well put up a sign and be done.
Locking both doors must be easy and natural, preferably with a control near the doorknob. I'm not going to try for an automatic solution, such as connecting the locks to the light, because I can't devise a reliable way to tell if the room is occupied.
The house occupants must be able to override the locks from outside the bathtoom (eg. to prevent someone from locking herself in). Having a key or pin hanging nearby is probably acceptable in most households.
This can be done but the solution may cost more than the average homeowner would be willing to spend. You will need:
2 "storeroom" locksets
2 electric strike plates, "fail safe" type
2 micro switches or magnetic switches that can detect if a door is closed
2 illuminated pushbuttons, the kind with the illuminator on a separate circuit
1 stepdown transformer to power the strike plates
1 latching relay matching the voltage of the transformer and strike plates
a roll of low voltage wire, amount depending on size of bathroom etc.
A storeroom lockset always opens from the inside by turning the handle, and is always locked and operated only with a key from the outside. (Usually the outside handle doesn't even turn.) A door with this fitting can be opened from the inside even in a panic and regardless of the state of the strike plate.
The storeroom lockset satisfies requirements 1 and 4.
A "fail safe" electric strike plate will hold the door locked from the outside when energized, and release it when the current is off. The plan is to maintain the strike plate current with a latching relay.
The micro switches or magnetic switches will unlatch the relay when either door is opened.
The required latching relay can be made from a single-pole single-throw normally-open relay, since the relay coil power can be made to flow through the micro switches.
The electric strike plates, micro switches, and latching relay satisfy requirement 2.
The pushbuttons should be mounted inside the bathroom near the doorknobs. I think the best place is on the door, just above the knob, with a tasteful plaque reading "LOCK BOTH DOORS". I have shopped for lock sets and strike plates with built-in switches but have found nothing, hence the pushbuttons.
I like to put pilot lights on everything so I would buy pushbuttons with built-in lamps wired independently from the switch contacts. Failing this I would use doorbell buttons and separate pilot lights. The purpose of the pilots is to reassure the bathroom occupant that both doors are locked. The voltage of the illuminators must match the voltage of the strike plates.
The pushbuttons satisfy requirement 3. This is the weakest part of the design because you are forced to use something made for a different purpose.
This is the kind of project I like to build just for fun. And the part I enjoy most, I might say the reason for undertaking the rest of the project, is the wiring diagram: