When you're lying down, every part of your body experiences the same blood pressure, except the highest point which is your willy. As dawn comes, your blood vessels relax and contract pushing all that blood up to the highest point.
When you get up and pee, the blood in your willy rushes back down into your lower body.
If you want to retain the erection and fuck, pee lying flat or use your legs as the blood is down there.