Differentiation is the world rule that sorts a hot body into layers. A body hot enough to melt any of its resources lets the molten part sort by density: resources lighter than the body's average rise to the surface, and denser ones sink to the core, each as its own layer. Solid layers stay where they are, between the two. This is how bodies form cores, such as a heavy iron core under a silicate crust.
See Glossary for melting points.