A thousand years is a compound noun with a (determiner meaning one) + a noun (thousand which is a cardinal number) + a plural noun (years).
The a has nothing to do with years as it modifies thousand meaning one.
Thousand is a noun modifier which has the following definition:
(grammar) a noun which is used attributively to modify or qualify
another noun, in a different way to an adjective. For example, in
railway station, railway is used as a modifier to describe what kind
of station it is.
A noun modifier doesn't take the plural form as adjective doesn't have the plural form. That's why the noun thousand is not taking the plural form in two thousand years and three thousand years.
The most important thing is the word a modifies thousand, not years as two and three do in the above examples. And thousand modifies years making years plural.
Note: There are a few exceptions where a noun modifier takes the plural form, i.e. a sports car, sports news, etc. But it is disputable whether the word sports is truly in the plural form.