My nephew used to leave their 3rd story apartment in the middle of the night ALL the time as a toddler <picture me'self and his mum just crossedeyed>. He was found playing in the parkinglot at 3am. He was found a couple streets over. He was found... each time... thank god... by a decent human being and not the bumper of a car going 30 or someone who hurts kids. He snuck out in the middle of the night over a half dozen times!!!
Fliplocks along the top will stop some kids. HE just drug a chair over and undid the flip lock. (Apt., so no alarm could be installed). Baby gate he just shimmied over. So my SIL installed a lock on his bedroom door. She was sighing with relief with some neighbors who were asking about her escape artist son that it wouldn't happen again. That night CPS came over, and insisted that she take the lock of the bedroom door or lose her kids right then and there. She cried for hours. Stayed up all night, he was up. And the next. He was up. She had to quit her job, because she had to stay up all night watching for him. (And yes, she both disciplined and punished him for leaving the house, to no avail). Of course, leaving the house was only PART of the dangerous things he was doing in the middle of the night. Homes are full of 'instant death' hazards in the form of drowning, crushing, knives, poisons, electrocuting... and maiming items like disposals, non-lethal crushing, stoves, etc.
Oy. That was a month of heart-attack-making.
We finally spent a couple hundred dollars on two great dane dog gates and stacked them vertically on top of each other across the door. THAT finally kept him in his room at night.