My daughter did that at 3. Even locking the door didn't work because she would
just cry outside the door until we woke up. I finally just got her old crib mattress and put it made up near the bed. She knew she was allowed to come in our room and sleep on the mattress but not in the bed.