The city of David - Bethlehem, called the city of David because it was the place of his birth. See the notes at Matthew 2:1.
Because he was of the house - Of the family.
And lineage - The “lineage” denotes that he was descended from David as his father or ancestor. In taking a Jewish census, families were kept distinct; hence, all went to the “place” where their family had resided. Joseph was of the “family” of David, and hence he went up to the city of David. It is not improbable that he might also have had a small paternal estate in Bethlehem that rendered his presence there more desirable.