Why do food items expire?
Expiring food items is obvious: for fresh food, it's almost always due to bacterial or fungal decay (spoilage).

Oxidization and sunlight doesn't really ruin food; it might alter the taste or decrease its appeal, although it remains edible even by first-world standards. However, it might destroy vitamins and other nutrients.

Medicines are a different matter. Some chemical compounds are slightly unstable, with half-lives measured in years. Instability can cause the compounds to randomly break into subcompounds that are ineffective for treating the intended condition at best and poisonous at worst. Unlike food, it's imperative to keep medicines away from sunlight (and oxidation in some cases) as both of these can further promote instability and breakage into subcompounds.

On the comment that Charles posted about medicine shelf life being much longer than advertised: The reason why they underestimate the shelf life is that it's better to have people throwing out potentially OK medicine than to have it sitting on a shelf for 20 years, going bad and sickening people, and prompting numerous lawsuits against the manufacturer. This type of deliberate underestimation in the name of safety is common in engineering - usually with weight limits advertised below the real weight limit. For example, an elevator able to haul 6000 pounds might be advertised as only 2000 because the manufacturer knows there's always going to be a few idiots who disregard the posted limit.