Why an erection can happen for “no reason”
An erection occurs when blood flow into erectile tissue increases and outflow temporarily decreases. The nervous system can trigger this during sleep, while waking, with a full bladder, from friction or pressure, during stress, or with no obvious conscious cause.
During puberty, changing hormone patterns and a developing nervous system can make erections frequent and unpredictable. They often become less disruptive with time, although healthy adults also have spontaneous and sleep-related erections.
An erection does not require desire. Bodies can respond during fear, medical exams, unwanted situations, or completely neutral moments.