There are officers in chatge of different watches on naval vessels. You don't want someone equal to the captain running things, potentially undermining each other. A senior officer would oversee the night watch while the captain sleeps.
They have duty shifts, each will have an officer in command. In a three-shift system (i.e. where each shift lasts 8 hours), you might have the captain commanding the day shift, the first officer the second shift, and another more junior officer on the night shift. Other times (like when Jellico commanded the Enterprise) there can be a four-shift system. If something important happens when the captain is off duty or asleep then the shift commander can always wake the captain - but the vast majority of the time (i.e. all the days in between episodes, which we never see) then nothing eventful happens during the night shift.
On the Enterprise D, Data often commanded the night shift since he didn't need any sleep, but in principle any officer (even at Lt Junior Grade or Ensign) could be put in command.
I ended reading up a load on this for a Star Trek Adventures game.