Dear Student,
Earth rotates because sun attracts the earth and thus pulls earth towards it and due to earths revolution around the sun, it tends to go away from the sun in direction of the tangent hence a rotational force acts on earth and it tends to rotate.
Regards.