Maybe an auto-pilot where the plane automatically descends to a breathable altitude if the pilot doesn’t respond to a regular stimulus and there’s high altitude (low) pressure within the cabin? Doesn’t seem more dangerous than the plane eventually crashing on its own somewhere due an incapacitated pilot.
Simpler and quicker solution is for pilots to wear an oxygen monitor. I have a Wellue O2 ring that monitors my oxygen level and vibrates when low, increasing in intensity if it doesn’t rise. While asleep it can nudge me to move and breathe better, and has woken me up when I didn’t do enough to improve my breathing (I do use both CPAP and oxygen). If the pilot had been wearing one (wireless, very comfortable) he would have known his oxygen level was dropping and been able to do something in time.