During the first three years of life, bladder storage capacity increases disproportionately relative to body surface area. By four years of age, most children void five to six times per day.
Development of bladder control appears to be a progressive maturation whereby the child first becomes aware of bladder filling, then develops the ability to suppress detrusor contractions voluntarily and, finally, learns to coordinate sphincter and detrusor function. These skills usually are achieved, at least during the day, by approximately four years of age. Nighttime bladder control is achieved months to years after daytime control, but is not expected until five to seven years of age
Basically it’s a combination of having disproportionate bladder sizes and not enough brain control to hold the flood gates back.
It’s both learned and related to development.
All mammals have the instinct not to “soil the nest”. We mostly train our babies out of this instinct by putting them in diapers and being totally oblivious to their signals that they want to pee, but it’s possible to keep it going – there is a thing called Elimination Communication which is one of those “parenting movements” with an awful name but effectively, it’s a googleable phrase which means you can find information about how to watch your infant for signs they are about to pee or poop and “catch” it in a little pot instead of using a diaper. This is also common practice in some non-Western cultures. Of course, if you want to do it at night you have to sleep in very close proximity to the infant. But doing this even very young babies will wake at night to pee and then go back to sleep.
So partly we train them out of it and then have to train them back into it again when we potty train. What happens when potty training is that toddlers are learning to associate the feelings of a full bladder/bowel with the imminent arrival of pee, and control the muscles around the urethra to hold it long enough to get to a toilet first? Children sleep much more deeply than adults – they tend to sleep through noise, for example, much more easily – and it’s common that for some time during and after potty training they are either not aware enough of the nerve endings around the bladder to pay attention to them even during sleep or they are just too deeply asleep to notice these sensations. Once they become more accustomed to paying attention to these signals, they’ll be more likely to wake up, assuming they are not too deeply asleep.
Secondly, the hormone part somebody mentioned below is also true but it’s not strictly related to why we wake up, more the amount of pee created. The adult body produces a hormone called ADH (antidiuretic hormone) during sleep which tells the body to produce less urine during this time, meaning that adults rarely produce enough urine at night to get into a desperate enough state to wake us up.
When we do, it’s likely unusual enough that this is a significant factor as well. For children who haven’t started producing this hormone yet (the exact age varies, but girls tend to develop it a couple of years earlier than boys, which is why boys are more likely to suffer from bedwetting for longer), the feeling of having a full bladder at night wouldn’t necessarily be unusual meaning it’s less likely to wake the child up.
Lastly there is the simple fact that adults tend not to be afraid of the dark and additionally are much more aware of where their limit for actually peeing themselves is, whereas children might delay getting out of bed because they are cold, scared, or just sleepy and they don’t have as good of a handle on that tipping point yet because they don’t have as much experience.
This is the same reasoning for why young children sometimes hold on so long that they just pee themselves because they were too busy playing or didn’t know that they didn’t have enough time to get to the toilet, whereas this rarely happens to adults without incontinence issues.