The first is the more correct of the two, although we would probably say
'By the time I was 20 years old, I had lived (or been living) with my father in this town for 10 years'.
The second sentence describes an impossibility, unless you are some kind of strange time-traveller. The period 'when I was 20 years old' lasted for exactly twelve months. So you could say, for example:
"I lived in this town with my father for ten months when I was 20 years old."
This means that I lived in this town for ten of the twelve months of that particular year. But as '10 years' is a lot longer than one year, there is no possible way that you can do something for 10 years during a one-year period! Time just doesn't work that way...