How do it know? Beats me. I only know that they do. The Moon knows, and it's a satellite. And the artificial ones shot into the air and hang around somewhere up there seem to know also. Apparently there are folks that do all kinds of fancy math to keep the man-made satellites flying around the Earth, but then there are other like Elon Musk who just wing it.
Artificial satellites do all kinds of useful things like spy on us for your Mom and fool us into thinking they're stars or something. Some of them provide GPS to make us think we know where we are. Plus, they let us look at the stars we can't see using binoculars. As a bonus, they guide nukes to their targets. Wouldn't want those to go off course by five feet or so, would we?
It probably works like the guy in the circus juggling things that are on fire except we can't see the hands because they're blocked by the curvature of the Earth. Oh, well. But just like the juggler, eventually it has to end and a satellite has to to come back to the ground. But those math guys have it all figured out so that the satellite will crash into the ocean far from land. They don't? Sucks to be us, then.