The Earth spins because it is formed in gathering disk of hydrogen clouds that settled down from the mutual gravity in the Solar System and needed to sustain its angular momentum. Think about it. Every hydrogen atom has its own momentum and as it drifts through the void these atoms grab onto each other and maintain an average momentum and could even average out to a perfect zero i.e. a still but that is unlikely to happen.
Why is the Solar System flat?
As the Solar system rotated at a great speed it flattened out into a disk like shape with a bulge in the middle where the Sun formed. This is the same structure that was followed throughout the Universe : the shape of galaxies, the black holes even down to the pizzas in restaurants.
And this spinning is maintained or is continued because of inertia. Another point to be noted is that they all spin in the same direction is due to their formation in the same Solar Nebula.
Learn What if the Earth Stopped Spinning?, visit : https://mocomi.com/what-if-the-earth-stopped-spinning/