This is a very good question. There a few main heat sources: Heat(and work) left over from the formation of the earth, work (potential energy) generated by dense iron sinking into the center of the earth and forming a core, and radioactive energy. Since the Thermal diffusivity of the materials that make up the earth is low, heat transport is very slow and thus the planet retains a significant amount of its heat.
Another reason why the earth is so hot, is that mantle convection is a very inefficient way to transport said heat, and thus the earth loses energy very slowly.
We know how hot the interior of the earth might be because of laboratory experiments, and also volcanic eruptions. How much energy(temperature) does it take to melt gabbro (mantle rock)?
Interestingly enough, the earth is cooling. And the inner core / outer core boundary is a freezing front (meaning turning from a liquid outer core to a solid inner core). Though, it is a very hot freezing front.