There are times when you hyphenate “10-year-old” and times when “10 year old” is unhyphenated. To know when to do which, the solution is as simple as finding where the phrase is, relative to the noun it describes.
When the Noun Follows the Age
When the noun follows the described age, you hyphenate the phrase such as in the following phrases.
I needed a new medication for my ten-year-old dog.
I recently sold my ten-year-old car.
My wife and I just replaced our ten-year-old roof.
The teacher absolutely beamed about her ten-year-old son.
When the Noun is Implied
Grammatically, it is not as secure to use 10-year-old as a noun instead of using the full phrasing, but there are times when brevity and flow are better served by shortening the sentence. These circumstances will still be hyphenated.
My ten-year-old was disappointed.
The ten-year-old slept long through the night before Christmas.
No ten-year-old looks forward to school.
Your ten-year-old is so well behaved.
When the noun precedes the age.
Not only with the noun precede the age in these circumstances, but the plural will be required evident as well.
When I was ten years old, I often wondered if I could be an astronaut.
When my daughter is ten years old, she will be the tallest kid in her classroom.
If that building is ten years old, it is possible it will need a new roof, given our current climate issues.
If the word “year” is singular, the hyphen is needed. If it is plural, there is no need. If the noun comes after the year or is implied, then hyphenate the phrase. If the noun, whether proper or pronoun, precedes the phase, then do not worry about the hyphen. You do not need it for this sentence.