All raw foods contain bacteria. If the food sits around the bacteria will grow and spoil it.
Some bacteria produce gas which will make a sealed can swell or even blow up
Some bacteria produce a deadly posion.
When a can is sealed no more bacteria can get in and the cook kills those on the inside.
If all bacteria are kills the canned food will keep for a long time.