Quick answer: The planets all orbit around the Sun in the same direction because they retain the rotation of the original cloud of gas and dust from which they formed.
If you had a spaceship and were able to blast off from the North Pole of the Earth and rise a few hundred million miles above the plane of the solar system, you could look down on the planets. You would be able to see that the planets are all orbiting in a counterclockwise direction around the Sun. This is no coincidence and neither is the fact that the orbits of the planets lie in nearly the same plane. Yet another clue is that the equator of our spinning Sun is well aligned with the plane of the orbiting planets.
These facts were known to scientists in the 1700’s. In the later part of that century, Immanuel Kant and Pierre-Simon de Laplace began to conclude that the situation could not have arisen by chance. They proposed that the planets evolved out of a primordial whirling disk. This helps explain the observations. Astronomers today agree that the basic idea of Kant and Laplace is correct although their ideas needed refinement.
The modern version of their idea is known as the nebular hypothesis. It is generally accepted by astronomers as the preferred description for how the solar system formed. According to the nebular hypothesis, the solar system began roughly 4.6 billion years ago as an immense rotating cloud of gas and dust called the solar nebula. Our Sun was born from the gas in the core of this protostellar cloud. As material was pulled inward by the gravity, the speed of rotation increased. The increased rotation rate caused the cloud to begin to flatten out into a disk shape.
Every planet started out as a grain of dust within the disk. Dust particles began to stick to one another by electrostatic attraction. As the clumps grew bigger they started to have larger and larger gravitational fields. Gravity attracted the larger chunks to one another causing collisions. The collisions became more numerous. The gentler collisions resulted in objects staying stuck together into bigger objects whereas the higher speed collisions caused destruction. The bigger objects, called planetesimals tended to survive since these were harder to destroy depending on the intensity of the impacts.
Over time the planetesimals aggregated into protoplanets. These were big enough to sweep out their orbits. The protoplanets then underwent a period of massive and violent mergers. Ultimately the greatest survivors of this process became the known planets of the solar system. Getting to this point is believed to have taken many millions of years. A large amount of leftover building materials was still flying around the solar system causing heavy bombardment of the planets. Today we see the evidence of these bombardments as craters. Some of that left over material is still around in the solar system. Although impacts still occur today, the really big collision events are much more rare.
The nebular hypothesis explains why the planetary orbits are all going counterclockwise as viewed from the north and why the Sun has a counterclockwise rotation on its axis. The original rotation direction of the solar nebula is still here today billions of years after the Sun began to shine and the planets emerged from their beginnings as tiny grains of dust in a whirling cloud.