During a dive, the loss of consciousness that may occur as the diver ascends to a shallower depth is due to oxygen deficiency (e.g. hypoxic blackouts).
In other words, the increased likelihood of suffering the effects of shallow water hypoxia occurs most in freediving and skin diving activities.
Most divers use special breath-hold techniques to try and extend their personal safety limits and bottom time.
However, in humans a buildup of carbon dioxide is the "stimulus" for breathing.
So, excessive hyperventilation (and holding your breath for too long) can cause hypoxic loss of consciousness (HLOC) - a lack of oxygen.
Fainting or passing out in water due to hypoxic blackout usually occurs in the last few metres of an ascent.
Hence, removing the urge to breathe at the surface before diving down can starve a diver of oxygen. When they start ascending, they may black out (e.g. become unconscious) and most likely they will not even realise that they are passing out.
Pro Tip: You should always freedive or skin dive with a buddy. They may be the only person that can recognise a diver experiencing shallow water blackout underwater.
Important: Anyone who experiences fainting underwater should seek medical attention to rule out the chance of suffering a secondary blackout.
The syncope occurs at shallow depth after the different phases of a breath hold dive have taken place. Put another way, aggressive voluntary hyperventilation before a dive causes low levels of carbon dioxide (CO2) and can lead to low oxygen (hypoxia) or anoxia (absence of oxygen).
Even though blackouts can occur in swimming pools, excessive hyperventilation is the likely cause (not changes in pressure).
The lowered partial pressure of oxygen (PPO2) at the final stages of a deep breath-hold dive can deplete the brain of oxygen towards the end of the dive, or immediately after surfacing, due to a reduction in ambient pressure.
For similar reasons, a "deep-water blackout" refers to the passing out in the shallow stage of ascent from a deep freedive.
One of the major hazards of diving with rebreathers is a hypoxic loss of consciousness during the ascent. Unless compensated, any abrupt drop of oxygen partial pressure in the breathing loop may be the contributing factor.
Important: Beginners who have regular headaches after surfacing from dives should review the industry standard relating to scuba diving breathing techniques and make modifications where necessary.
Important: The tutorial video [16:21 seconds] presented by DAN explains how gas toxicities and pressure affect the human body during a dive.