The 5 years is a rule of thumb because there are so many things that will effect the helmet. Age as stated will cause it to break down, heat like it was stored in a garage where it could get really hot. The oil from your skin and hair will break it down. If there are certain fumes around when it is stored can cause an issue. Of course how much it is used and treated.
If you have a helmet that is kept in a dark closet in the house and not used very much, yes it will last a lot longer than 5 years. If you have the helmet in the garage or other hot environment, use it every day, is left to bake in the sun, banged around a lot, and is surrounded by solvent fumes it will probably need to be changed out in 2 years.
The 5 years is not gospel, it is a guide but a person really needs to take a look at how the helmet is used and cared for. Use your best judgement and don't get too wrapped around the axle about it.
Personally I change mine about every 5 years but I ride all of the time, my helmet will have about 50 to 60 thousand miles on it and a lot of time baking in the desert sun. At 5 years my helmet has considerable wear and tear.