While other systems play contributing roles, erection is primarily a neuro vascular process.
In the resting (flaccid) state blood flow is minimal. The 2 structural compartments of the penis, the paired (2 tubes) corpora cavernosa and the corpus spongiosum, are interspersed with a complex network of arteries, veins, and nerve terminals. (Arteries are blood vessels responsible for carrying oxygen-rich blood away from the heart to the body whereas veins are blood vessels that carry blood low in oxygen from the body back to the heart for reoxygenation).
The organ is innervated by somatic and autonomic nerve fibers. The somatic nervous system transmits sensory and motor signals to and from the central nervous system. An autonomic nerve pathway involves two nerve cells. One cell is located in the brain stem or spinal cord. It is connected by nerve fibers to the other cell, which is located in a cluster of nerve cells (called an autonomic ganglion). Nerve fibers from these ganglia connect with internal organs.
The tunica albuginea is the dense, fibrous elastic covering of the corpora cavernosa in the penis.
In a flaccid penis, there is a balance between blood flow in and out. When a man becomes aroused, blood flow to the penis increases significantly. As the penis expands and hardens, veins that normally carry blood away from the penis are compressed against the tunica albugines. This limits the amount of blood that flows out of the penis. With more blood flowing in and less blood flowing out, the penis enlarges and becomes fully erect. (Source: Andersson KE, Wagner G. Physiology of penile erection. Physiol Rev. 1995)
When the blood vessels of the corpora cavernosa relax and open up, blood rushes in through the cavernosus arteries to fill them. The blood then gets trapped under high pressure, creating an erection.
An erection begins with sensory and mental stimulation. During sexual arousal, nerve messages begin to stimulate the penis. Impulses from the brain and local nerves cause the muscles of the corpora cavernosa to relax, allowing blood to flow in and fill the open spaces. The blood creates pressure in the corpora cavernosa, making the penis expand and creating an erection.
The tunica albuginea (the membrane surrounding the corpora cavernosa), helps to trap the blood in the corpora cavernosa, sustaining the erection. Erection is reversed when muscles in the penis contract, stopping the inflow of blood and opening outflow channels.
As it relates to the pelvic floor muscles (here is a detailed post on pelvic floor muscles), erection is caused by contraction of the ischiocavernosus muscle, which compresses the penis against the ischium (the curved bone forming the base of each half of the pelvis), obstructing the blood flow through the dorsal veins.
Nitric oxide (NO) is the principal factor increasing blood flow into the penis. Penile engorgement and the pelvic floor muscles maintain an adequate erection by impeding outflow of blood by exerting pressure on the penile veins from within and from outside of the penile tunica. Extrinsic pressure by the pelvic floor muscles further raises intracavernosal pressure above maximum inflow pressure to achieve full penile rigidity. Aging and poor lifestyle choices are associated with metabolic impediments to NO production. Aging is also associated with fewer smooth muscle cells and increased fibrosis within the corpora cavernosa, preventing adequate penile engorgement and pressure on the penile veins. Those same penile structural changes occur rapidly following the penile nerve injury that accompanies even "nerve-sparing" radical prostatectomy and are largely prevented in animal models by early chronic use of a phosphodiesterase type 5 (PDE5) inhibitor. Pelvic floor muscles may also decrease in tone and bulk with age, and pelvic floor muscle exercises have been shown to improve erectile function to a similar degree compared with a PDE5 inhibitor in men with erectile dysfunction (ED). (Source: Meldrum DR, Burnett AL, Dorey G, Esposito K, Ignarro LJ. Erectile hydraulics: maximizing inflow while minimizing outflow. J Sex Med. 2014 May;11(5):1208-20. doi: 10.1111/jsm.12457. Epub 2014 Feb 13. PMID: 24521101.)