When electrical devices such as computers operate the electrical resistance causes heat which needs to be removed. There are three ways to transfer heat: conduction, convection and radiation. The components with electrical resistance such as resistors and inductors radiate heat from the component to the air and several components with higher wattage ratings are mounted on a metal platform which increases the component's surface area to also effectively transfer heat into the air.
The heated air inside the computer housing needs to be removed faster than it builds up. Too much heat can damage circuitry or cause the electrolyte chemicals in capacitors to expand and possibly explode. When the computer is idle usually the holes in the housing are enough to ventilate the heat. When the computer becomes active and too much heat builds up a sensor will switch the cooling fans of the computer on. If the sensor can't switch the fans on at a certain temperature point the sensor will then cause the computer to shut down to prevent heat damage.
Some more expensive computer models use liquid cooling rather than fans to remove excessive heat.