Because:
When an animal dies, bacteria inside the carcass produce methane as part of the decomposition process.
If this is not let out of the body gradually it builds up, exploding at the first opportunity.
Whales are the most extreme because their huge size makes the consequences of a gas build-up so much greater