People used to think that sleepwalkers acted out their dreams. They also thought that sleepwalking had to do with epilepsy, hysteria, dissociative disorders or even your own secret wishes.
To be perfectly honest, no one knows exactly why people sleepwalk, but what scientists do know is that it most frequently happens to children and occurs during the deepest stages of sleep, stages 3 & 4.
This is your deepest sleep where your brain waves are the slowest in contrast during REM sleep or rapid eye movement your brain activity is much more active and this is the stage in which most of your dreams occur and to keep you fromb acting out those dreams your body’s muscles become temporarily paralyzed so it makes sense that mostly walking occurs in the stage other than REM sleep.