Your internal body clock, AKA your circadian rhythm, responds to light and dark and regulates physical and mental processes that occur at different times.
Fascinatingly, your gut microbes work on a similar clock and have different functions during the day and at night but a lot of that depends on your own body clock and if you start going to bed at crazy times, it can disrupt your delicate community of microbes.
sleeping allows your body to recuperate and recalibrate. your gut needs sleep just as much as the rest of your body. your gut microbes even have their own body clocks!