It started after he was potty trained. A couple of weeks after I considered him to be potty trained (just over three), I went to get him from a nap. He was still asleep, but he had pooped in his underwear. I talked with him and told him if he needed to go potty, he could get out of bed and go. A little light went off in his eyes. He had obviously never considered this a possibility.
For a couple of days after that, he would come to me during his nap and tell me he had gone potty. He was going only a small amount, and only so he could get out of bed. We then had another talk and I told him that he could go potty if he needed to, but that he couldn't take advantage of that freedom and go potty whenever he wanted to get out of bed. We talked about it until he understood. He was good after that and no longer took advantage of the situation.
About a month and a half to two months ago (Brayden was about a month shy of 3.5), he again began to test the limits on this freedom. He no longer used going potty as the excuse; he hunted for every excuse he could think of. He would come to me with question after question. I taught him how to tell time and what time was acceptable to get up. At first that worked fine, but then he would just sit and stare at the clock instead of sleep at all. He went to taking maybe one nap a week. Something had to be done.
One thing I did was move certain privileges to after nap time, and those were conditional upon him staying in bed. For him, this was TV time. He didn't get TV time unless he stayed in bed for his nap. That worked for a while, but he again started to come up with excuses to get out of bed.
A big part of this I knew was a result of my being so sick for my first trimester. He had more freedom during that time and had started to become 'wise in his own eyes.' There was some retraining that needed to happen here.
I tried rewarding him for taking a nap rather than simply punishing him for getting out of bed. That didn't seem to make any impact on him. I started to wonder if he was ready for rest time rather than naptime. He didn't misbehave the days he didn't take a nap (other than not staying in bed). For whatever reason, I just didn't think he was ready for full rest time. I knew he didn't need a nap ever day, but he also wasn't ready for the expectation of a nap or two a week.
Over time, we re-established proper freedoms for his age. We also had one pivotal day where I finally found the currency that worked for him. I told him if he got out of bed, I was going to take his clock away. Well, he did, and so I did. He was very upset about this and started to cry. I told him he had made his decision. He cried for about thirty minutes before he finally just fell asleep.
Since that day a little over a month ago, he has stayed in his bed flawlessly. He is now sleeping most days of the week. He has his clock back without problem.
If you have a toddler or child getting out of bed, hopefully this story can help you with problem solving. The first thing to consider is your child's freedom level. He probably is being allowed more freedom than he can handle. Then, search out proper rewards/consequences for his actions. Good luck!