During the formation of the Earth, when it was a hot molten sphere, elements had the chance to move freely and accumulate where they wanted. So the distribution of elements occurred during that time. Dense elements, such as iron, made their way to the inner core.