So after the “Big Bang “. Matter and gas was flung out in all directions. The Earth and other planets stars were formed by the early rotation of matter and gasses. But what set up the rotations in the first place.
Planets spin because the vector sum of all the momenta of the pieces that formed it. For that sum to not result in an angular component would be a remarkable coincidence.
The axis of rotation is different from the magnetic poles. This difference creates force for the earth to rotate on its axis. The same is the case with all planets in the Solar System. Moon doesn't have Magnetic field; hence it does not rotate on its axis.