This is a fairly well known problem. One year I had to climb through the underbed hatch, push the bed up and crawl my way through, not a pleasant experience but a very interesting site.
If you flick the catch up, inadvertently or deliberately on the way out then the door will lock. Best thing is to strap a spare door key somewhere to the chassis or axle.
Colin