The other two answers mention 'summer camp' type environments.
My answer is more focused at family camping, but has some relevance to both: With younger children it can be very simple, although possibly not the most comfortable
:You sleep across the doorway.
For any child to get out at night they need to climb over you.
If you think they could sneak around you (if you have a tent with a wide door, for example), you could look at putting a string through the zipper with a loose bow, but I'd tend to advise against this as in an emergency it could cause confusion.
With older children (I'm thinking 7 to 10 year olds) you can run a brightly coloured cord from the tent to the latrine area, and depending on the environment, you could leave a couple of night lanterns at the tents (this has its drawbacks in attracting insects)
Above that age, as long as they are sensible, just make sure they have some obvious signposting - natural features etc - which they can use to navigate back.
As long as you aren't in dangerous country (bears, cliffs, etc.)
older kids want to go exploring at night.
In any case, make sure they have good torches (flashlights) and a whistle before going out alone.
outdoors.stackexchange.com/users/66/Rory Alsop
My experience with children summer camps says the children are so afraid of the dark that they won’t go into the night unless their bed is on fire, and even then very reluctantly.
When they need to pee they’ll go the least possible distance from their tents and if they have to visit the latrines, they will wake up their mates or rather wait until morning (which doesn’t always work, but that’s a different story).
I think the only real possibility is some kind of sleepwalking.
That would be quite hard to guard against, as no amount of schooling will make a difference.
If you really do want to cover this scenario, I think you would have to resort to keeping guards or employing some technical solution like this (randomly googled).
outdoors.stackexchange.com/users/103/zoul
Pleased to see no-one's mentioned locking the door in some way - just to reinforce for anyone that may come across this question, that's definitely what not to do, since in an emergency you want to be able to get out as quickly as you can.
My first instinct is to ask if it's even a risk that's worth accounting for?
Unless you're talking about particularly adventurous or mischievous children many will be too scared to venture out into a dark, unknown, unlit area without knowing their way back.
If you decide it is then there's a number of things you can attempt to do, though realistically the only thing that's going to be dead set in stopping them is sleeping in shifts.
First, make sure the adults sleep closest to the door and the children closest to the back - this way they'll struggle to get out unnoticed if they have to climb across 2 or more fully grown adults without waking them.
You could also use a GPS / radio signal tracker, but this relies the child keeping it on them which they presumably won't do if they think they're not allowed out.
Another point in relation to this though is to lay down the ground rules, and lay down the consequences.
If they know the possibility of them getting caught is there, and this possibility would result in wrecking the trip somehow for them all, they'll generally be a lot more cautious about attempting to sneak out!
outdoors.stackexchange.com/users/74/berry120
If it's a large number of kids or if they aren't your own kids then yes, parents should work in shifts.
You're responsible for them and you can't be certain of their behaviour.
Otherwise, kids should follow the same discipline as at home, which is that you don't leave your room/tent after you go to bed, and that if you do have to get out to go pee or whatever that you stay within eyesight, or ask an adult to come with you.
If you're really worried, give them all whistles and have them wear them around their necks.
outdoors.stackexchange.com/users/231/furtive
Any system which relies on preventing kids form exploring while outdoors seems to be both self-defeating and unlikely to work.
My advice is to talk to them about what they should do if they do get lost so they can help in their own rescue.
Similarity putting too strong a prohibition on wandering off is only likely to make them more prone to panic and forget safety instructions if they do.
Simple things can make the campsite easier for anybody to find if they do get lost at night. set up a perimeter line with high visibility (even glow in the dark cord)
this gives a bigger target to find in the dark
Put out a safe light overnight in a visible spot, a chemical or solar powered lantern is ideal have an agreed system for signalling, for example if you notice somebody is missing blow a whistle 3 times every minute and set up extra lights ideally a strobe.
Ideally 'home' lights should be coloured eg blue or green to make them more obvious and avoid any confusion with lights from roads towns etc.
Give everybody a whistle and key-chain light on a string if you put it in a bracelet
then kids are more likely to keep it on.
It is also a good idea to conduct a 'lost' drill early in the trip, it should be easy enough to make this a game.
For anybody getting lost the biggest danger is panic so going through the emergency procedure in a fun way will greatly improve their confidence.
Teach kids that if they realise they are lost they should stay put and shout out.
I would also endorse the 'buddy' system from a previous answer, pair kids off and encourage them to look out for each other,
emphasise that if they are worried about their buddy they should ask an adult for help.
My own feeling is that giving kids a bit of agency in looking after themselves and each other is by far the best way both for them to get the most out of the experience and keep them safe.
outdoors.stackexchange.com/users/8820/Chris Johns
When camping in more remote areas with young kids, how can you make sure they don't take a stroll and get lost in the middle of the night?  We won't be near lights, established "bathrooms", etc.  The adults will be asleep as well, and I'm hoping for a solution that does not involve sleeping in shifts.
How can you prevent kids getting lost at night while camping?
outdoors.stackexchange.com
<safety><camping><children><night>
outdoors.stackexchange.com/questions/1187
outdoors.stackexchange.com/users/127/Russell Steen
Giving kids a bit of responsibility to look after themselves and each other is the best way for them to get the most out of the experience and to keep them safe.  It is important to lay down the ground rules. It is a good idea to conduct a 'lost' drill early in the trip and teach them to shout out if they are lost. Adults should sleep closer to the door and parents may choose to sleep in shifts. A perimeter line may be useful as well as a night-time safety lantern Giving kids agency, talking to them and conducting lost drills can help. Adults can sleep closer to the door, work in shifts and arrange lights/perimeters.
You cannot stop kids from exploring, but you can set ground rules and give them agency. You can conduct 'lost' drills and prepare kids, though they will generally be afraid of the dark. Parents can work in shifts and sleep closer to the door. Lights and perimeters can help.