Morning erections might actually relate to the timing of rapid eye movement (REM) sleep. As part of normal sleep patterns, called sleep architecture, transitions occur throughout the night between the various sleep stages. As morning approaches, the REM period becomes prolonged. Therefore, when you first wake up, you are often coming out of REM sleep.
In addition to the dreams that are characteristic of REM sleep, the penis also becomes erect and engorged with blood during these periods. This is technically called penile tumescence. When this occurs in the morning, it may be referred to in slang terms as "morning wood" or "morning glory."
Therefore, morning erections are secondary to the timing of REM sleep and the natural physiological processes that are associated with this sleep state in men. The erection typically goes away within a few minutes after awakening. A lack of morning erections may suggest a problem with erectile dysfunction.

