Notice the Indefinite Article in (1), before the noun 'boy' (which may be omitted since the two people talking know who 'he' is.) In (1) 10-year old is used as an adjective/adjectival phrase, qualifying the noun 'boy'. (note the hyphen).
In (2) 10 years old is a description - there is no Indefinite article, and no noun following it.
That is the pattern:
use a hyphen and the singular when it is an adjective
and
use the plural and no hyphen when a description.
Examples:
It's a 40-foot tree.
This tree is 40 feet tall.
This is a 2-metre cable.
This cable is 2 metres long.