Cans of spoiled food may swell, and it is usually taken as a sign of spoilage, but canned food may be spoiled even if the can does not swell.
If cans do swell, it can be for two reasons, one chemical and one biological.
Acid foods, like tomato juice, canned pineapple or almost any canned fruit, may attack the lining of a metal can, and one of the by-products of the chemical reaction is hydrogen gas.
The gas exerts pressure inside the can, causing it to swell.
What food scientists call a hydrogen swell poses very little health risk, and you could probably eat the food, though it might taste metallic, but don’t take a chance, because the other cause of swelling could be fatal, and a consumer has no reliable way of telling the difference.
The second reason for swelling is that inadequate processing of the canned food could have left behind living microorganisms that are capable of reproducing, especially anaerobic organisms, the ones that can live in the absence of oxygen.
The organisms give off gases, mostly carbon dioxide, that can cause the can to swell.
This swelling can be a sign of very serious food spoilage that could cause illness or even death, like botulism. Other less dangerous microbes can also cause swelling, but to tell the difference, lab tests would be needed.
A rule of thumb for consumers is not to use cans that have pressure in them, on the chance that it might be of microbiological origin.
When in doubt, throw the can out.