In theory, yes. Most models of star projectors run from mains AC power or DC through a USB port, so they will run as long as they are plugged in. However, some models are battery-powered, meaning you run the risk of the battery running out of power overnight.
It’s important to check the manual that comes with your star projector before you leave it running for extended periods of time, as some models may become hot after prolonged use. Always resort to the manual if in doubt and follow the instructions.