Is there a contingency for such a situation, where one of the pilots leaves the cockpit, the other pilot is incapacitated (for example losing consciousness) while the first pilot is still outside the cockpit and can not reenter the cockpit. If there is not, is that not a huge flaw, as multiple pilots are meant as a redundancy.

Edit: This is in my opinion not a duplicate of [this question](https://aviation.stackexchange.com/questions/11677), since the big problem in my question is the door to the cockpit being only openable from the outside.

In the linked question, the answer is simply "both pilots being incapacitated at the same time is highly unlikely". The scenario I described is not highly unlikely. One of two pilots being incapacitated is not improbable and the door to the cockpit is only openable from the inside.

So if **one pilot is incapacitated** while being temporarily alone in the cockpit, the other pilot is "automatically" locked out of the cockpit.