Sleepwalking, also known as somnambulism or noctambulism, is a phenomenon of combined sleep and wakefulness. It is classified as a sleep disorder belonging to the parasomnia family. It occurs during slow wave sleep stage, in a state of low consciousness, with performance of activities that are usually performed during a state of full consciousness."
Source Wikipedia
The cause of sleepwalking is unknown. A number of, as yet unproven, hypotheses are suggested for why it might occur, including: delay in the maturity of the central nervous system, increased slow wave sleep, sleep deprivation, fever, and excessive tiredness. There may be a genetic component to sleepwalking."
[ Source as above ]
Most sleepwalking episodes last less than 10 minutes, and tend to affect children more than adults. It's known that various factors, including lack of sleep, alcohol, drugs, infections etc. can increase the chance of a sleepwalking episode.
Further information UK NHS
Also see: Sleepplugin-autotooltip__plain plugin-autotooltip_bigSleep
"The purposes and mechanisms of sleep are only partially clear and are the subject of intense research"
Source Wikipedia"
Although extensive research in humans and animals has shown unequivocally that sleep is essential, the reasons why it's required are as yet unknown. Long term sleep deprivation not only severely impairs cognitive and motor skills, it's now been shown that it can cause physical damage to brain structure - and, in extreme cases, irreversible damage.