There is a hypothesis that it prevents you from wetting the bed. When your penis is erected you can’t piss yourself (or it is more difficult).
Sometimes when I go to the toilet with erection I need to wait for erection to go away in order to do the job.