I found this answer from the sources at the very bottom of this answer!
“The penis has two chambers inside it called the corpora cavernosa. These chambers extend from the head of your penis deep into the pelvis. The insides of these chambers are made of spongy tissue and have the ability to gain blood volume and grow in size.When one is at work, hitting the gym, or running errands, the arteries supplying blood to your penis are only partially open. This provides the blood flow needed to keep your tissue healthy. In response to physical or mental stimulation, your brain sends signals to trigger a hormonal response that allows those same arteries to open completely. Open arteries allow more blood to enter the corpora cavernosa. The blood enters faster than it can leave through the veins. The veins get compressed, trapping blood in your penis. This chain reaction lets you achieve and maintain an erection.When your brain stops sending signals that indicate sexual arousal, the hormonal response ends. Your arteries go back to their normal state and your penis returns to a flaccid state”