"5 years ago" functions adverbially, which means it modifies the verb "have lived". Now, present perfect verbs are incompatible with specific dates/time, and that's why  below is ungrammatical (*). The phrase '5 years' directly modifies a present perfect verb:
 I have lived there *5 years ago.
 I have lived there *5 years.
The word 'ago' has nothing to do with anything, really. In example  'ago' is missing and the sentence is still ungrammatical.
If a specific date/time directly modifies a present perfect verb, the result will be ungrammatical, but if we disguise the specific date/time, by putting it inside another phrase, so the verb doesn't "see" it, we get a grammatical result, like this,
 I have lived there for 5 years.
 I have lived there since 2000.
The phrase '5 years' no longer directly modifying the verb 'have lived'. It's part of (or inside of) 'for. . .'. The entire phrase 'for 5 years' modifies the verb 'have lived'. '5 years' is disguised, or hidden, sort to speak, from the verb's eyes. The same holds true for the phrase 'since 2000'.
Note,  and  below are ungrammatical. "ago" can't stand on its own (), and "5 years", a noun phrase, doesn't function adverbially on its own ().
 I lived there *ago.
 I lived there *5 years.
It's a pair:
a long time + ago
3 hours + ago
"ago" comes from agone, which meant gone by:
5 days have gone by = 5 days agone => Modern English: 5 days ago
Hope that helps,
- For Teachers