It is a well known phenomenon, known as glottis reflex. I already wrote about this in other posts.
It is a neo-natal reflex, which is very useful for avoiding children to breath water if the fall in water.
Usually this reflex attenuates and disappears in a few years. When I was teaching finned swimming to children 6 years and above, only 1 over 4 was still experiencing troubles breathing from the snorkel without a mask.
Going to adults probably this falls down to 1 over 10, but is still a relatively frequent problem.
The reflex is triggered by a neurotransmitters on the face, around the nostrils. Usually a mask cover these receptors, avoiding the problem. But if the mask is flooded or removed, the reflex can be triggered, and you cannot breath anymore.
People suffering of this problem can be trained to overcome the temporary block with a number of exercises and techniques. One very effective is to swim at the surface breathing from the snorkel without the mask. Initially with eyes closed and nose closed with fingers. Then you gently release one nostril, then the other, open one eye, and then the other. Repeat it for many hours, until you can get proper control of the reflex.
This kind of training must be repeated periodically, as if you do not practice it for years, the risk that the reflex kicks in during the wrong moment can resurface.
Very interesting.