My son woke up every night from the age of about one until two and a half years of age, with exactly the same problem. He would wake up around 2am most nights and start crying in his sleep, for hours throughout the night. We thought at first he was too cold, or too hot, or having nightmares, so we let him sleep in our bed. But this still didn't resolve the problem. This went on for months and the doctor was unable to help. When he was a little older and starting to speak he told us he was 'sore', pointing to his nappy. We noticed then that he had an erection which would last for a very long time. We tried changing the brand of nappy as we thought he might be suffering an allergic reaction to the elastic in the nappy. We also tried cloth / washable nappies. But this made no difference. We left him without nappy on, but this didn't work either. We took him to the doctors telling him about the erection problem, and were referred to the hospital. He had a physical examination and blood test to check if there was a medical reason for the erections, but everything was normal. We were in despair.
One night he was in so much pain in his sleep that he was wimpering again and I was so exhausted and exasperated not knowing what to do. I picked him up out of bed, half asleep and took him downstairs in my arms. We sat upright on the couch and I was cuddling him. It was then I noticed that he started to have a wee in his nappy, then straight after that, he completely relaxed and slumped in my arms as if relieved. The erection went away. I put him back into bed and he slept peacefully thoughout the night. I came to the conclusion that everytime he had an erection in his sleep, he needed a wee, but for some reason couldn't go in his nappy when laying flat. So each night afterwards, when he woke up crying, I would pick him up and stand him on the floor, supporting him in this position. Then whisper to him repeatedly to have a wee in his nappy, which he did every time. After that, I'd put him back in bed and he would sleep throughout the night. What a massive relief!! We also reduced the amount he drank just before bed, as he was used to drinking milk to send him off to sleep. This worked a treat and very soon afterwards, he was sleeping right the way through without waking up at all. I hope this post helps anyone else out there who is going through the same problem.