That's called "<em>Geothermal</em>" energy.
"Geo ..." always means something about the Earth.
"Thermal ..." always means something about heat.
Geothermal energy is used in places where there's a lot of heat that's not too far under the ground, like in places above ancient volcanos.
The system is built with pipes running deep down into the ground and then back up again, and then running water is pumped through the pipes. The water picks up heat from down under and brings the heat up to the surface, where it can be used to heat homes and buildings, and turn steam turbines to generate electricity.
Geothermal is the MAIN source of energy in Iceland.