The head gasket is a flat piece of material (can be made of many different substances) place between the head and block surfaces. It performs several different functions. (I've fully described a head gasket in this answer.) It's main purpose is to keep things in their place (oil, water, combustion, etc).
There are several different types of head gasket failures:
- Coolant leaks into the cylinder
- Oil leaks into coolant passage
- Combustion gasses leak into coolant passage
- Combustion gasses leak between two cylinders
(NOTE: There may be more, but this list will suffice for this answer.)
When an overheating issue is caused by a blown head gasket, the primary failure which occurred causing this is when combustion gasses leak into the coolant passages (usually coolant is leaking into the cylinder at the same time). When combustion occurs, large pressures occur inside the cylinder which can force the combustion gasses into the cooling system. This creates an over pressure inside the cooling system, which forces coolant out through whatever means is available. That's usually the radiator cap. Inside the cooling system, large pockets of gas form which then allows for overheating of the engine. It's a vicious cycle which will remedy itself rather quickly ... with a dead engine.
Usually things happen the other way around, though. Usually an overheated engine can cause the head to warp, which can cause a head gasket failure. The overheating condition can be caused by any reason (lack of coolant, blocked radiator, pump failure, etc). It still results in major engine damage.