There are layers to this, some of which are definitely not ancient mysteries. We sleep because the environment has a day-night cycle. If any task an organism must perform is better done during the day, then evolution has a very clear gradient towards only doing that thing during the day. That leads to doing other things at night, since it would be comparatively advantageous to do them at night, given whatever task is most benefited from being done during the day.
If there wasn't a day-night cycle it's unlikely that the brain would have evolved to crucially depend on approximately a night's worth of time of not using the body.