Why do all the planets orbit the Sun in the same direction and in nearly the same plane?
Because all the planets formed out of debris that orbited our sun…. The orbits of the planets are coplanar because during the Solar System’s formation, the planets formed out of a disk of dust which surrounded the Sun. Because that disk of dust was a disk, all in a plane, all of the planets formed in a plane as well. Rings and disks are common in astronomy. When a cloud collapses, the conservation of angular momentum amplifies any initial tiny spin of the cloud. As the cloud spins faster and faster, it collapses into a disk, which is the maximal balance between gravitational collapse and centrifugal force created by rapid spin. The result is the coplanar planets, the thin disks of spiral galaxies, and the accretion disks around black holes.