Certain foods are normally refrigerated, but after cooking can be kept at room temperature for a few days at least. An obvious example is cheese -- e.g. cheese-topped rolls normally have a best before date a few days after they reach the shelves. Many cake ingredients have to be refrigerated, but then the resulting cake can be kept at room temperature.

How can we tell which foods undergo this change? Alternatively, what's a change -- is it just drying and water activity (it might be, given that dried hard Italian cheese is shelf-stable).

The question is about the science but the motivation is things like savoury flapjacks as appetising carb-heavy snacks for cycling, when the sweet stuff becomes unappealing. For it to be worth making a batch, they should have keeping properties on a par with biscuits (cookies/crackers), i.e. almost forever if airtight (so longer than my first example, but that's because the bread would go stale).

I don’t know the full answer, but a lot of it has to do with the concept of “water activity”. Milk will spoil because it has sufficient water to allow microbial growth. If you remove the water and make powdered milk, it is shelf stable. If you add the milk with flour and bake it, the overall moisture is low enough that it will not quickly spoil.
– Kevin NowaczykNov 3 '17 at 17:09