The specific reason changes from food to food, but usually it’s one of two: either there are some chemical reactions that make it bad, or there is some microorganism (usually moulds) that starts growing on the food and ruins it.
The first mechanism is for example what makes milk or butter expire. The chemical substances contained in milk, when in contact with air, undergo a process called “oxidation”. This means they combine with the oxygen in the air to form different substances – which are not exactly nice to eat. One of the stinkiest chemical compounds in existence is called “butyric acid” – which comes from “butter”, since it forms in expired butter (not by oxidation – in this case it comes from combination with the aqueous vapour in the air, but it makes little difference)!
The second mechanism is rather obvious and applies, for example, to bread: we like to eat our bread, why shouldn’t other life forms like it as well? And that’s exactly what moulds are about: microorganisms (usually floating around in the air in small quantities) which settle down on our bread and start eating it and growing on it. This gives bread a not-very-healthy green colour and an unpleasant smell. The unfortunate thing is that after eating, moulds of course have to… well… poop too. Which is kind of a crude way of expressing it, but the point is that they produce waste products which can be toxic as well – and generally are always disgusting. Hence, moulded bread is better thrown away. If you just leave it for a few days, however, bread only becomes harder because it loses a bit of its water (which evaporates): this makes it less tasty but not unhealthy, and if you toast it, for example, it hardly makes a difference.
Some foods expire in “special” ways. A peculiar example are potatoes. Potatoes are actually roots of a plant. So when they are dragged out of the earth they still try to sprout and grow. Expired potatoes look green and have sprouts all over them! The problem is that when they sprout, potatoes also produce large quantities of a substance called “solanin” – which is downright poisonous. Potatoes are one of the most dangerous things to eat when expired – of course, if there are only a few sprouts and you cut them and the part of the potato surrounding them away, they’re fine. Basically, you should cut away all green pulp!