...a five-year-old was...
...knew the 12-year-olds who...
The word old/olds is part of the hyphenated compound noun when the word year is singular. The word old/olds is a combining form, and the combination is hyphenated.
...is five years old...
...knew he was 12 years old...
When the word years is plural, the word old is an adjective. There are no hyphens in the combination.
Happy punctuating!
Margie