They used an underfloor heating system called a hypocaust.
The floor of the baths was raised by pillars. Hot air from the furnaces would travel through this space under the pools on its way to the roof through space left in the walls. This way the pools would heat up without bringing the water in contact with the smoke from the furnace.