The reason for the rotation of earth and planets arise from the concept of formation of our solar system.
In the beginning solar system was a big cloud of dust and gases. This cloud began to collapse, flattening into large disk, rotating faster and faster continuously, as they collapsed, their gravitational orbit set those dust and gases to spin. As a result, the clumps of massive particle formed within that disk were going to naturally have some sort of rotation. Due to conservation of angular momentum spinning went faster and faster for e.g., skaters speed up their rate of spin as they brought their arms closer to their body. Also due to gravitational pull from all directions, the clump of massive particles became a round planet, our earth is also one of those clumps. Inertia of motion keeps the planet spinning continuously on its axis unless any external agent resists this rotation.
Actually earth’s rotation is also affected by tidal pull of moon, it slows down at the rate of about 1 millisecond per year. Earth’s spinning was faster in the past. At that time, a day was about 22 hour long only.