A planet was once molten and gravity forced all the lighter elements to float to the surface in order of density. Gas is the lightest, Water is the second and Rocks are the third lightest elements. Rocks floated to the surface because they were lighter than heavier metal such as Iron, Nickel and Magnesium.