On commercial aircraft, every flight safety critical component is at least dual redundant, and some are triple or even quad redundant. If any one channel of these redundant systems fails, then the other(s) can take over the safe operation of the aircraft. However, a failure of one flight safety critical system (almost) always results in an emergency being declared, and a swift landing at the nearest suitable airport.
IMO, pilots should be considered a flight safety critical component in the same way. There are two of them so that if one "fails", the other can take over the safe operation of the aircraft. However, currently one can leave the cockpit (for a waz or dump or whatever) at which point the dual redundancy has been compromised. There is no other system on the aircraft where you are allowed to compromise the dual redundant nature of a safety critical system in this way.
The mechanicals of modern airliners are now so safe that such pilot "failures" are becoming statically important. Last years Ethiopian Airlines hijacking into Geneva was a pilot lockout event. MH447 might be too. Now this one possibly. There are others too if you look back - Silkair, EgyptAir etc.
The pilots in charge of hundreds of lives in the fragile aluminium tube behind them need to accept that they are a dual redundant component and behave accordingly. On short haul (sub 4hr) flights there should be no need to leave the cockpit. Go before you leave or you use a pee bag like fighter pilots have to. Longer than 4 hours and you need 3 type rated pilots in the cockpit.