Guys get morning wood because our bladders fill up during the night and begin to press against our prostate, causing arousal. Our dicks don’t just feel the sun coming up and think “My time has come”
While in REM sleep, your body turns off some neurotransmitters to regulate body functions. And one of those neurotransmitters, Norepinephrine, is the one in charge of stopping erections. Basically, when REM decreases the Norepinephrine levels, testosterone is free to pump blood into the area and cause your sleep erection. In addition to making for wonderful middle school jokes, morning wood is actually important because it pushes extra oxygen into the region, and helps keep your penis healthy and functional.
Alternatively, if you’ve got a full bladder when you go to bed, it can bump up against your spine and automatically give you an erection to stop you from wetting the bed.