The layered structure of planets is explained by the fact that the collisions that occurred while planets were forming released a lot of energy. This energy heated the interiors of the proto-planets, and sometimes melted them. Once molten, denser material would sink to the center of the planet, causing the layered structure we typically see today.