The coalescence of matter into a body will conserve the angular momentum of its individual parts. The Earth did not "start rotating", the Earth was a cloud of particles, rocks and gas, in a loose orbit around a cloud of particles rocks and gas that was to become the Sun and the rest of the Solar System. It was already rotating before it formed.
Where does the rotation come from in the first place?
1] Take two particles in empty space.
2] Give them each a random velocity in a random direction.
3] Place them close enough so that they gravitationally interact.
4] When they eventually collide, they will not exactly cancel each others' motion out (There is only a single, astronomically small chance of this happening - it requires both particles to collide with each other in a direct line, with no tangential motion relative to each other i.e. they were on a collision course to begin with). So, when they collide, they will stick together. They will retain any residual tangential motion that doesn't completely cancel out. This effect is cumulative.