The earth "spins" (rotates) on its axis based on the action of the materials that accreted to form it, and also on any large collisions it might have undergone. Like the one in the large impactor theory about the way the moon came to be in orbit about the earth.