The Old Testament said Jesus would be a descendent of David. That being the case, Matthew 1:1-17 shows how St. Joseph is a descendent of king David. But since Joseph wasn’t Jesus’ biological father, how did Jesus fulfill this particular prophecy?
Joseph’s geneaology is listed because, by Joseph’s marriage to Mary and by his acceptance of Jesus as his own child (cf. Matt. 1:18-25), Joseph became Jesus’ legal father. Thus, Joseph’s ancestors became Jesus’ ancestors.
For an example of the Old Testament precedent for this, see the story of Jacob’s adoption of Joseph’s sons Manasseh and Ephraim (cf. Gen. 48:3-6). Jacob claims these sons of Joseph as his own and states that they are equal in standing as his sons to his blood sons Reuben and Simeon (his first- and secondborn sons).
Christian scholars have long thought, however, that because the prophesied relationship between David and Jesus appeared to be much more than a legal relationship (cf. Rom. 1:3), that the Virgin Mary must also have been of the house of David. This is certainly possible, although we do not know for certain. However, it is interesting that Mary is specifically named in the Matthean geneaology alongside Joseph (cf. Matt. 1:16). Along with the other mentions of women in Jesus’ geneaology, this was very unusual as Jewish mothers were generally not counted among ancestors at that time.
If this is true, then Jesus would have been the Son of David both by his legal relationship to Joseph and by the blood relationship he received through his Mother. However, by the laws of the time, the legal relationship would have sufficed to count Jesus as the Son of David.