Planets orbit the Sun due to the force of gravity. The Sun's gravity is not stronger than that of any planet; rather, its mass is significantly larger, allowing it to exert a stronger gravitational pull. When planets formed, they had initial velocities that, combined with the Sun's gravitational pull, resulted in elliptical orbits in accordance with Kepler's laws of planetary motion. They don't fall into the Sun because their velocity is high enough to continually "miss" it.
When you throw a rock from a tower, it starts with an initial forward velocity that propels it horizontally, while Earth's gravity pulls it downward. If thrown at a sufficient speed, the rock's forward momentum will balance out the gravitational pull. Here's how:
Gravity continuously pulls the rock towards the Earth's center, curving its path downward.
The rock's initial velocity propels it forward. This forward motion tries to move the rock in a straight line.
Earth's surface curves away beneath the rock as it moves forward. So while gravity pulls it down, the ground is also "falling away" from it.
The result is that the rock is in a perpetual state of "freefall" around Earth. It never hits the ground because its forward speed ensures that as it falls, Earth's surface curves away at the same rate.
This balancing act between gravitational attraction and forward momentum is what keeps the rock (or a satellite, or a planet) in orbit. It's always being pulled toward Earth, but its horizontal speed prevents it from ever actually reaching Earth. It's like the rock is constantly "missing" the Earth as it falls, creating a stable orbit.
The speeds that allow planets to orbit the Sun stem from the formation of the Solar System. During this time, material with lower angular momentum became part of the Sun, while faster-spinning material escaped. The remaining material coalesced into planets, retaining enough velocity to maintain stable orbits.
The Sun and planets share the same direction of rotation because they originated from the same spinning nebular cloud. As it contracted under gravity, it spun faster due to angular momentum conservation. This led to a flattened disk, which is why planets orbit in a relatively flat plane called the ecliptic.
In a simple system without other major celestial bodies, a planet would have a circular orbit. However, the gravitational effects from other planets, especially gas giants like Jupiter, cause orbits to deviate into elliptical shapes.