I had a similar predicament when I was 6. Our house is old, and the locks and door knobs and stuff sometimes don't work (well, used to. The doors we didn't close got removed (due to an incident of my sister smashing her head into one), and the ones we did got new locks because of this fair incident). I locked the door as I went to the bathroom (my parents love to traumatized me and had pranked me on several occasions and I was sick of it), and the lock got stuck. I was in there for a good hour before my dad busted down the door.
Thinking back on it now, I wish I would've listened to my parents when they told me the lock was screwed up. But then again, we got a new lock on it now, so maybe it was for the best?