What happens to a whale when it dies? Depends on the whale.
When pretty much any creature dies, humans included, gases begin to build up as the body decomposes. This is why gangster stereotypes make use of concrete overshoes, and why bodies of people that are found in bodies of water are known as "floaters". Whales, too, fill with gas; but most whales are extremely heavy (and dense) creatures. They don't float around too much. Some, like Northern Right Whales and Humpback Whales, have enough blubber to make them quite buoyant; Sperm whales float, too, because of the buoyancy of their spermaceti.
Whales are an important food source. Carnivores of varied types - sharks, other fish, plankton - feed on the whale meat at one point or another. Recent findings indicate that whale carcasses form the basis for rich mini-ecosystems on the ocean floor.
Some of the more buoyant carcasses, however, become (in the words of Chilean whale experts) "a skeleton suspended in a semi-liquid mass within a bag of skin and blubber." Eventually the bag ruptures; the bones sink and the blubber continues to float at the surface. In a recent incident, blubber from a sperm whale washed ashore in Chile and temporarily baffled experts as to just what the "blob" was.
References and further reading: