The reason is physiological - and aplies to a lot of adult men as well -
the bladder is situated next to the Cowper's gland, which is responsible for the erection. When the male is lying down, and the bladder fills, it presses on the Cowper's and gives an involuntary erection, which subsides when the male stands up, the bladder moves off the gland, the erection subsides again.
That's why a lot of guys wake up with the 'morning glory' - perfectly natural, nothing to panic over.