When they look a bit tired. I have a couple of helmets. I use a cheaper one for commuting and replace it every few years. At about £40 used daily it isn’t really a cost concern.
Mostly this +1
I usually have one ‘road’ and one ‘trail’ helmet on the go at any given time. They generally last until they start to look scruffy and/or they take a big enough knock to justify replacement. I doubt they get anywhere near 5 years on average!
Having said that I just ordered a new one because my old one had cracked clean through at the front and I don’t actually remember any really bad crashes. So it’s worth inspecting them periodically and replacing out of caution as it had obviously been weakened by a relatively minor crash at some point (or rather, I hit my head harder than I thought and it did it’s job).
Even if replaced at 5 years despite no signs of damage, that’s a cost of about 20p/week for peace of mind.