All the major planets orbit the Sun in the same direction because they all formed out of a single, rotating disk of gas and dust, and that original spin had to be conserved.
Formation from a spinning cloud
The Sun and planets formed from a giant cloud of gas and dust called the solar nebula that was slowly rotating. As gravity pulled this cloud inward, it spun faster and flattened into a disk, much like spinning pizza dough spreads into a flat disk.
Conservation of angular momentum
Because of conservation of angular momentum, the material in this disk kept rotating in the same overall direction as it collapsed. Planets grew (accreted) from clumps in this rotating disk, so their orbits naturally followed that same direction around the young Sun.
Same plane and direction, with exceptions
Collisions and interactions in the early disk tended to erase orbits going the “wrong” way or at steep angles, leaving most surviving planets in nearly the same plane and direction. A few oddities, like the unusual spins of Venus and Uranus, are likely due to giant impacts or later gravitational disturbances rather than a different original orbital direction.
