Why does the earth rotate?
As a consequence of early solar system development.
The Earth formed during the rest of solar system formation. A beginning solar system starts basically as a rotating disk with lots of chaotic collisions.
It is hypothesized that the Earth was struck by an object that caused it to spin very quick (in fact, a day on early Earth is estimated to have been on the order of a handful of hours). Now, we know that one day is about 4x as long at 24 hours.
The rotation of the Earth is a consequence of conservation of angular momentum. From collisions and its initial rotation within the early solar system disk, Earth has maintained some of its initial rotation.
Now, Earth is slowing down little by little. Although this isn't noticeable to us, as it is on the order of milliseconds per century.