1. He has lived in the town three years ago/last month/in 2003.

2. He has lived in the town before.

3. He has lived in the town in the past.

4. He has lived in the town recently.

5. He has lived in the town lately.
----------------
#1 is not correct, is it? What about #2 to #5? Are they all grammatical?

1 is not correct.

The rest are correct.

No, only #1 is grammatically incorrect. Here's an explanation for each sentence:

1. "He has lived in the town three years ago/last month/in 2003."
This sentence is grammatically incorrect because the verb tense does not match the time expressions. To correct it, you can say "He lived in the town three years ago/last month/in 2003."

2. "He has lived in the town before."
This sentence is grammatically correct. It indicates that he has experience of living in the town at some unspecified time in the past.

3. "He has lived in the town in the past."
This sentence is grammatically correct. It implies that he lived in the town at least once in the past but does not specify when.

4. "He has lived in the town recently."
This sentence is grammatically correct. It suggests that he lived in the town at a time not too long ago.

5. "He has lived in the town lately."
This sentence is grammatically correct. It means that he lived in the town in the recent past, indicating a more recent timespan than sentence #4.