The "a" goes with "mere", not with "three years" (and yes, it's grammatical).
You could replace "a mere" with "only" or "just":
The Supreme Court overruled this decision just three years later.
When used with small quantities, the indefinite article is often coupled with mere. Oxford Learner's Dictionary lists several examples:
- It took her a mere 20 minutes to win.
- A mere 2% of their budget was spent on publicity.
- He seemed so young, a mere boy.
- You've got the job. The interview will be a mere formality.
The word mere is not unique in this regard; the word paltry is often structured the same way:
- This account offers a paltry 1% return on your investment.
Note: The article would not be used if merely was used in place of a mere:
It took her merely 20 minutes to arrive.