Why are the planets closest to the sun rocky?
Because of Radiation.
In the Beginning of the Solar system, the Proto-Sun was more Luminous and Radiant than it is today, about 10-20 times more Luminous. The Sun was radiant enough to drive away gas from the inner Solar system leaving behind the rocky cores which are now terrestrial planets. The Sun was radiant but it was radiant enough to drive all the gas away from the outer Solar system, thus those rocky cores gained a gaseous mantle making them gas giants.