There are several reasons why the earth's interior is so much hotter than its surface. First, the earth was formed through gravitational compression of many particles; a portion of that original heat remains, trapped beneath the crust. Second, some of the heat in the middle layers of the interior are hot because the deeper core is cooling and releasing heat. Third, a major portion of the heat comes from radioactive decay. As unstable elements like uranium break down, they release heat. All of this combines, and, since all is trapped beneath a rocky mantle, much of the heat is simply contained there.
There are three main sources of heat in the Earth.
Some heat was generated by gravitational contraction as particles came together to form the earth and pulled together under the force of their own gravity- part of a process called planetary accretion. This heat has not escaped over the last 4.5 billion years because rock is an insulator and slows the transfer heat to the surface of the planet. Most of the heat in the earth is attributable to this source.
The second source is radioactive elements concentrated in the crust and mantle, not the core. Heat production occurs in the Earth's lower mantle due to radioactive decay of potassium, uranium and thorium. The effect is like a heat blanket wrapped around the planet which adds heat and further aids in trapping heat inside the planet. The amount of radioactive material in the earth diminishes as it decays to stable end-products over time, thus the amount of heat produced by radioactive decay in the Earth is always on the decline.
The last source of heat is also due to planetary accretion- but is related mainly to the heat generated by impacts. In the early stages of Earth's formation there would have been milions of impacts between planetoids and debris of all sizes. That heat is also trapped and slowly being radiated into space.