Imagine thee planets interacting through gravity, mathematically how should they come and rotate in a same plane, like planets and sun?
The answer is that the situation you suppose does not lead to a planar geometry. The reason for that is that gravitational encounters between discrete bodies like planets rarely have any dissipative properties - that is, potential energy is swapped for kinetic energy and vice versa. The outcome for a multiple planetary system that starts off with randomly inclined orbits would be chaotic.
The reason that the planets orbit the Sun in the same plane is because the planets formed from a disk of gas and dust that was already in a planar geometry. The reason for this is that the gas and dust is dissipative - kinetic energy was lost (in the form of heat and radiation) whilst angular momentum was conserved. The outcome is a disk.