When a planet is heated through gravitational pull, where is the energy taken from?
Jupiters moon Io is heated through the gravitational pull of Jupiter, but when Io is heated because of this, where does that energy come from? How does conservation of energy work for this effect, where is energy "lost"?
TL;DR: The energy ultimately comes from Jupiter's rotation.
Io is tidally locked; it has the same orbital and rotation rates. If Io was in a circular orbit, the tidal forces on Io would merely result in a "frozen tide" on Io. There would be no heating because Io's shape would not be changing. However, Io's orbit is not quite circular. This means the tidal forces vary in magnitude and direction over the span of an orbit. This stretches and squeezes Io, which in turn results in Io's heating.
There's a tension between the other Galilean moons, particularly Europa, and Jupiter with regard to Io's orbit. If those other moons didn't exist, the dissipation of those tidal forces on Io would tend to circularize Io's orbit. The outer Galilean moons tend to make Io's orbit more elliptical. Which wins of Jupiter's tendency to make the orbit more circular or the outer moons to make the orbit more elliptical depends on two things: the ellipticity of Io's orbit, and how warm Io's interior is.
The degree to which Io responds to the Jovian tidal forces depends on the ratio of Io's $k_2$ Love number to its tidal dissipation quality factor $Q$. The quality factor is high when Io is cool, low when Io is hot. Io cools as it's orbit becomes closer circular. The outer moons can then push Io into a more elliptical orbit, and that's when Io warms up. Now the Jovian influences dominate, and Io moves toward a more circular orbit. Heating and cooling a large moon takes some time, so this means there's a time lag in the response. A nice hysteresis loop sets up.
These tidal effects go both ways. Io raises tides on Jupiter. How Jupiter responds to those tidal forces depends on the ratio of Jupiter's $k_2$ Love number to its tidal dissipation quality factor $Q$. Various estimates of Jupiter's quality factor $Q$ were extremely high before humanity sent spacecraft to Jupiter. Now that we've accurately seen the Galilean moons in action for quite some time, it appears that Jupiter's $Q$ is rather low.
There's a lot of dissipation in the Jovian system. The energy certainly has a place to go. As for where it comes from, that's simple. The actions by Io on Jupiter slows Jupiter's rotation rate. This is the ultimate source of energy for the Galilean system.
References:
Hussmann, et al. "Implications of rotation, orbital states, energy sources, and heat transport for internal processes in icy satellites," Space Science Reviews 153.1-4 (2010): 317-348.
Lainey, et al. "Strong tidal dissipation in Io and Jupiter from astrometric observations," Nature 459.7249 (2009): 957-959.
Peale, "Origin and evolution of the natural satellites," Annual Review of Astronomy and Astrophysics 37.1 (1999): 533-602.
Wu, "Origin of tidal dissipation in Jupiter. II. The value of Q," The Astrophysical Journal 635.1 (2005): 688.
Yoder, "How tidal heating in Io drives the Galilean orbital resonance locks," Nature 279 (1979): 767-770.
Note that Lainey et al. disagree markedly with Wu on the value of Jupiter's Q, 36,000 (Lainey et al.) to 109 (Wu).
To add to Dancrumb's answer and deal more specifically with energy, page 21 of the MIT thesis says the following:
As a secondary object orbits around a primary body, the gravitational force of the primary causes a distortion in the shape of the secondary, and vice versa. We can refer to one body as the perturber and the other body as the extended body, but both objects are causing and experiencing distortion. This distortion is the tidal bulge. Because the body experiences friction as the bulge is raised, the bulge is offset from the line from the primary to the secondary. This offset is quantified as the tidal phase lag $ \delta $, which is often related to the tidal quality factor $ Q = cot \delta $.
If the extended body is rotating significantly faster than the perturber is orbiting, the tidal bulge will lead the perturber. Then the bulge has a positive torque on the orbit of the perturber, increasing the semimajor axis. If the extended body rotates more slowly than the perturber orbits, the bulge will lag behind, creating a negative torque that decreases the semimajor axis of the orbit. The change in orbital angular momentum of the perturber is counterbalanced by change in rotational angular momentum of the extended body. Any change in the total rotational plus orbital energy is counterbalanced by heating in the extended body as a result of friction.
So apparently, in this example the rotation rate of the "extended body" (the one that the satellite is orbiting) is slowed down, decreasing the body's energy due to its angular momentum, and this energy is split between increasing the orbital angular momentum of the satellite (the 'perturber' above) and heating it via tidal heating due to friction. Page 22 adds:
Energy is transferred to the satellites in the amount $ n_0 T_0 + n_1 T_1 $, where n is the mean motion and T is the torque from Saturn on each of the satellites, and some of that energy goes into expanding the orbits. The rest is dissipated as tidal heating in the interior of the satellites.
It may be in other examples that the energy for heating comes primarily from a decrease in orbital angular momentum of the satellite rather than decrease in rotational angular momentum of the main body though, see Chris White's comment on this answer:
In the case of tidal heating due to a highly eccentric orbit, the energy often does come from the orbital energy of the smaller body being heated. The size and eccentricity of the orbit decrease with time. This is one of the proposed mechanisms for hot Jupiters to move inward toward their stars.
Io undergoes synchronous rotation as it orbits Jupiter. As a result, the same part of Io faces Jupiter all the time.
Since Jupiter is so massive and Io orbits so closely, Io's shape is distorted due to tidal forces, that is to say the difference between the gravitational pull on Io's closest side to Jupiter and its furthest side to Jupiter are different and this results in it being slightly stretched.
Equilibrium comes when the tidal forces are balanced by Io's internal structure acting against further distortion.
So far, no heating.
Io's orbit is disrupted by Europa's orbit. Io and Europa orbit Jupiter with periods that have a ratio of ~2:1.
The result of this interaction is that Io's orbit is forced to be more eccentric than it otherwise would be (elliptical and not centred on Jupiter).
Thus, its distance from Jupiter is constantly changing. Thus the tidal forces on Io are constantly changing. Thus its shape is constantly changing.
The work done to change Io's shape is what leads to the heating.
As to where the energy comes from, these actions tend to slow the orbital and rotational velocities of the bodies involved. This reduction in rotational energy goes into heating the planet.