Cooking mostly makes food safer to consume. However, canning is a classic example of how "cooking" food can go wrong. That is why there are strict guidelines around the process.
Let's say you take some raw fruit, rich in sugar, wild yeasts and lactobacillus. Oh, and some naturally occurring botulism and ecoli for good measure. Let's say you macerate this fruit and place it in a couple of different jars.
Jar 1, raw: This jar gets capped and put in the fridge overnight. You have toast with preserves the next day and paint the walls brown because you didn't kill the ecoli by cooking it.
Jar 2, raw but fermented: This jar gets capped and placed in a warm window where over many months it ferments into a tart, alcoholic beverage. The sugar content, alcohol and acidity have effectively preserved the fruit and killed the small amount of botulism and ecoli present, making it safe to consume (note that fermentation has it's risks too, but that's not the point here).
Jar 3, "cooked" / canned: This jar gets capped and placed in a boiling water bath for 15 minutes. From the perspective of immediate consumption, the ecoli is dead and the botulism hasn't been given enough time to form toxin. You eat this on toast two days later, and everybody is happy. Now let's imagine that you left this jar unopened on the shelf for two years. Your fruit preserves were not cooked long/hot/acidic enough to prevent the botulism spores from growing and forming botulism toxin. Now you have toast with jam and within a day you are laying paralyzed on the kitchen floor.