According to an article released by Facebook page IFLS, morning erections or medically known as "nocturnal penile tumescence" is primarily caused by the activities of the nervous system and endocrine system.
Nocturnal penile tumescence happens during Rapid Eye Movement (REM) sleep also known as deep sleep. When a person is at his dreaming state, areas of the brain become active. The activated parts send messages to the male genitalia allowing erection. In addition, male testosterone levels are also at its highest in the morning. This contributes as a factor for morning erections.
While men are used to this kind of phenomenon, it also serves different health purposes. Morning erection alerts men of their full bladder in the morning. It also signifies well-maintained oxygen in their genitals which is good for the muscles.
Generally, science considers morning erection as a sign of good health. Lack of morning erection may be associated with erectile dysfunction.
Source: TNP, IflScience