One possibility is claustrophobia in the shower, leading to a panic attack. If you have been standing under it for some time, this can be the cause. Try and keep the head under shower for just a few seconds, as long as you can comfortably hold the breath. Other than that, it can be due to vasovagal attack, postural hypotension, anemia, heart causes, thyroid problems and pinched nerve at cervical spine. If this is happening again and gain then do discuss this with your doctor and get yourself examined. Take care!
The medical advice given should not be considered a substitute for medical care provided by a doctor who can examine you. The advice may not be completely correct for you as the doctor cannot examine you and does not know your complete medical history. Hence this reply to your post should only be considered as a guiding line and you must consult your doctor at the earliest for your medical problem.