The creation of our planet, the Earth, was achieved by the forces of gravity over millions of years, melding together different rocks into a sphere. This process, known as accretion, let the Earth grow into the size it is today, with the help of Thea, a large planet that turned into our moon.
These rocks were not all uniform in composition, with some being silicate rocks and others were icy rocks. Some were even metal. During the formation of Earth, the materials inside the planet shifted in a process known as differentiation, where the denser materials shifted down into the core while the less dense materials shifted up to the surface. It is just like oil and water being mixed together then separating after time. This is the reason why we have a rocky surface on the earth and crust, while the core of our planet is composed of denser metals such as iron and nickel.

This can also be shown on a larger scale to the solar system. The solar system started out as a cloud of cosmic dust that started to spin, flatten, and heat up. This is the birth of our star, but also the birth of the rocks that will become our planets. In a sense, this collection of mass in a disk is similar to accretion.
Furthermore, the heat near the center of the early solar system is much more intense compared to the outskirts. This causes a difference in what rocks can feasibly condense. Metals and rocks have higher melting temperatures, so they can exist closer to the center of the sun. These metal building blocks can also exist farther away from the sun, but there are also icy rocks and gasses that have cooled to a solid state. This means that the center of the solar system can have planets made of only denser materials, while the outer planets have less dense materials making up their composition. This process, although dictated by temperature and condensation rather than gravity, is very akin to differentiation.
In both cases, the density of the material, which influences relative position from other materials as well as melting temperature, has shaped both our planets’ and solar system’s layout.