Breathing with Clogged Nose during Sleep
Most people with colds/allergies/stuffy noses don't die in the middle of the night. Why?
Prevention of oxygen deprivation is powerfully regulated. If insufficient air intake is possible through the nose, the mouth opens automatically (regulated by the autonomic nervous system. If you exercise, at some point, nasal breathing isn't enough, and you start mouth breathing. It's not conscious.

The autonomic nervous system (ANS)... is a division of the peripheral nervous system that supplies smooth muscle and glands, and thus influences the function of internal organs. The autonomic nervous system is a control system that acts largely unconsciously and regulates bodily functions such as the heart rate, digestion, respiratory rate, pupillary response, urination, and sexual arousal. This system is the primary mechanism in control of the fight-or-flight response.
Within the brain, the autonomic nervous system is regulated by the hypothalamus. Autonomic functions include control of respiration, cardiac regulation (the cardiac control center), vasomotor activity (the vasomotor center), and certain reflex actions such as coughing, sneezing, swallowing and vomiting. Those are then subdivided into other areas and are also linked to ANS subsystems and nervous systems external to the brain. The hypothalamus, just above the brain stem, acts as an integrator for autonomic functions, receiving ANS regulatory input from the limbic system to do so. (emphasis mine)

The answer is a complex interaction between blood pH and oxygen/CO2 receptors and the autonomic nevous system.