Just like comets roam the universe, there are planets that don’t belong to any solar system.
When such planets enter an established solar system, forces are unleashed to either capture or eject it from the system. This can be understood in terms of what has already been said about orbits, meteorites and comets.
First thing to note is that a rogue planet, although gravitationally attracted to other planets, and the central star, will have an electrically charged surface that makes direct collisions unlikely.
We don’t have to worry about rogue planets crashing into Earth. However, that’s not to say that a close encounter with such a planet would be entirely harmless.
At the very least, there will be a very strong ion wind associated with such an event. This will cause severe storms on Earth, way worse than anything anyone alive has ever experienced.
If the encounter is sufficiently close, there will be a discharge between the two planets as they seek to equal out their charge difference. This will be extremely destructive, wiping out all life wherever the discharge hits. A valley will be carved into each of the two planets as the discharge moves along their surfaces.
The net result of this will be repulsion. The rogue planet will either be ejected from the solar system or captured by it.
If captured, the newcomer will push and jockey for position. It will seek an orbit in harmony with the other planets. This may require other planets to change their orbits to allow for the newcomer.
There will be chaos, but it will be relatively short lived. The combination of electrical repulsion and gravitational attraction acts like a shock absorber. The rogue planet will be rained in. It may not take more than a few decades to integrate the newcomer into the solar system.
After a few thousand years, it will be as if the rogue planet has always been a member of the family. However, evidence of a violent past will remain.