Welcome to PF alchemist !
Friction and nuclear decay of the heavier
elements that "sank in" during Earth's formation.
In stars there's nuclear fusion of elements in
the center. They're extremely hot inside and
As for other planets, I believe that the same
thing happens there too, but the specifics
depend on the planet's formation and elements
present. I'm not sure about the way it works
in gas giants though.
I'm not sure what you mean by - "what purpose does
the molten core... serve ?". It's just there.
Live long and prosper.