At least one of my cars would lock if you started the engine and then got out and accidentally shut the door, which is why I always carry two set of keys to this day. On the truck I have now they lock when you put it in gear like you say.
Mine auto-lock at around 5 or 10 mph, probably to avoid that locked-out problem you describe.