This originates from when quality helmets were all constructed of fiberglass.
The hardening of fiberglass resin is a chemical reaction that never really stops. So with time, the fiberglass does weaken and become brittle.

Many of todays helmets are different types of plastics and I don't think that the 5 year rule applies to them.
Now if the foam gets compressed, then the deceleration effect of it is reduced, so that may still be a reason to replace periodically.