Sleeping in your car is not illegal as long as you're parked in a public location or a place you can legally be.
However parking somewhere that says prohibited for overnight parking would be illegal.
Although most times you'll just be asked to leave the area.
You could legally park overnight or for awhile in the daytime and sleep in your car at a rest stop.
I've done this myself on long road trips when I needed a quick nap or needed to sleep overnight.
But just be aware of your surroundings and if you feel uncomfortable just leave and go elsewhere.
In general not illegal to sleep in your car.
However, there are many exceptions to that rule, and laws for sleeping in your car will vary from state to state.
And, in general, private businesses are free to ban drivers from sleeping overnight in their parking lots.
Not everyone chooses to sleep in their car.