It's an evolved response the body does to conserve oxygen use in the brain. Consciousness shuts off, but the brain is still active. For example, someone who blacks out this way will not get water in their lungs--a part of the brain that is still active keeps your mouth shut so that no water is accidentally inhaled.
Freedivers try to avoid blackouts, but in this context, there are established safety procedures and it is not nearly as bad as you may think.