Heating the can makes the water inside it boil, turning this liquid into gaseous water vapour. The water vapour adds to the number of gas molecules inside the can and pushes some of the air out of the can. The escaping air and water vapour keeps the pressure inside the can the same as the pressure outside. If the air hadn't escaped (perhaps if the can was sealed) the can would have started to inflate (just before it exploded!).
Putting the can upside down in the cold water seals the can; no more air can flow into it. Instead, the water vapour inside the can cools down as the sides of the can cool in the cold water. This gaseous water vapour turns back into liquid water and the pressure is reduced in the can. With no air able to flow back into the can, there is an imbalance between the air pressure outside the can and inside. The pressure outside pushes on the can until the can crumples.
The can will stop crumpling once it has reached a volume where the pressure inside equals the pressure outside (or that it is squeezed so tightly that the force from the air pressure can't deform it any further, but really you need a vacuum pump for that!).
Use protective eyewear when working with hot liquids and a bunsen burner. Don't touch the can with your hands whilst it is heating and when you are putting it into the cold water. Also be aware that the can and any remaining liquid in it will be warm. Do not touch the crumpled can until you are sure it is cool.
Source: NESTA
Date: 10 February 2008
Subject: Physics
Suitability: Over 14s Over 16s Professionals Teachers