During the formation of a solar system, there are lots of planets which haven't organized themselves into stable orbits yet, so many planets probably get ejected.
At the end of its lifetime, a star undergoes mass loss which probably destabilizes planetary orbits (e.g., by breaking resonance structures) causing more planets to become ejected.
How dense is space with planets unattached to stars? Also comets, of course. Navigation hazard?