Due to a stream from early stages of the Sun, the gaseous layers of the planets close to the star blew away, leaving them rocky.
Our solar system is a cosmic family. There are members in this family with different characteristics, such as the small rocky planets that are the kids and love staying close to Sun; the bigger gas giants keep their chaos away from the kids, while the icy cold members hardly ever get close to the Sun, but they love it all the same.
All the planets were born from this remainder of the nebula. The dust particles first got together to make the cores and then the gases surrounded these cores. It is believed that more than eight (the current number of planets in our solar system) planets might have formed during this chaotic time, but they all collided with each other and formed newer and bigger planets and cores.
What Happened That Made The Rocky Planets Come Closer To The Sun?
As mentioned earlier, the solar system in its youth was very chaotic (just like angsty teenagers). All the planets, and even our own Sun, were in exotic and excited states. There were many collisions and explosions and heat waves passing between them. All of these cataclysmic incidences changed the nature and order of our solar system in various ways.
Once upon a time, the rocky planets we see now also had huge gaseous layers around them, just like the gas giants and ice giants. However, during its angry young years, the Sun let out huge streams of energy and matter into the solar system. The rocky planets, being the closest to the Sun, took the full force of these streams. This made the gases of these planets part ways with them, leaving just the rocky part behind, which went on to become the terrestrial planets.

The remaining four planets were too far from the Sun to experience these streams, so they stayed relatively unaffected and formed the gas and ice giants of today.
Do All Solar Systems Have Rocky Planets Closer To Their Stars?
So is it a pattern that we see everywhere? Do other solar systems in other parts of the universe show the same trend of having the rocky planets closer to the star, while the massive gas giants are quite far away?
The answer is no.
Scientists have found many solar systems in which gaseous planets (many of which are even more massive than the gas giants of our solar system) are the ones closest to their stars.
Conclusion
The answer to the question of why the rocky planets are closer to the Sun lies in the past, in a time full of chaos for our solar system, where huge streams of energy and matter coming from the newly formed Sun blew away the gaseous layers of the planets closest to it, leaving them small and rocky. How lucky for us!

References (click to expand)
- The Terrestrial Planets - NASA Solar System Exploration. The National Aeronautics and Space Administration
- Gas Giant | Planet Types – Exoplanet Exploration. The National Aeronautics and Space Administration
- Why do astronomers call Uranus and Neptune ice giants?. Astronomy
- The Outer Planets: How Planets Form. The Laboratory for Atmospheric and Space Physics












