It tends to happen when you are bored. The Body confused it with relaxation and the nervous system triggers the Same area of the lower spinal cord that makes you get a boner. Its connected to how you need to feel safe and relaxed to some extent to get it up. Also causes extreme anxiety to give men momentary erectile Dysfunktion. Its all a network of "Glitches that don't cause damage" in our Software so it never got patched by evolution. Like sneezing when seeing bright light.