From what I remember, over 30 years ago, when the Earth was first formed it was fairly hot. It was formed by accretion of material from space. At first it was a fairly homogeneous mixture. This material started out fairly hot from changing gravitational potential energy to heat. It was also more radioactive than current day Earth, it was 4.5 billion years younger after all, This heat built up faster than it could radiate out to space and was enough to melt the iron, nickel, and some other denser materials in the Earth. This migrated to the core, releasing even more heat in the process. That was roughly the theory then, I don't think it has changed much since then.