It is only through Joseph that Jesus can claim Davidic lineage. Even if Mary’s lineage could be confirmed as Davidic (there is no certain evidence to this effect), it is ultimately not relevant, for lineage was not traced through the mother. Raymond Brown cites the Babylonian Talmud: The family of the father is regarded as the proper family, but the family of the mother is not regarded as proper family.
1 And so it is necessary that Joseph remain on the scene. This is stressed by the angel when he encourages Joseph to bring Mary to his house: he refers to Joseph explicitly as Joseph son of David.
This Joseph may feel that he is not needed because God has mysteriously taken his place. The angel tells him that he is needed after all, that his Davidic lineage means something here! The Holy Spirit is certainly the author of this life, yet Joseph too is critically important. So Joseph cannot out of fear step back! God does not at all want this relationship terminated. Divorcing Mary will jeopardize her child’s Davidic lineage. “Joseph, son of David, you can’t go away! You must be the husband of Mary so that the child to be born might be the great Son of Davd!”
But how can it really be said that Jesus is of the house of David, if Joseph is not his father in a physical sense? In a classic work, J. Gresham Machen responds to our concerns:
In the New Testament Jesus is presented in the narratives of the virgin birth as belonging to the house of David just as truly as if he were in a physical sense the son of Joseph. He was a gift to the Davidic house, not less truly, but on the contrary in a more wonderful way, than if He had been descended from David by ordinary generation. Who can say that this New Testament representation is invalid?… In the second place, the relation in which Jesus stood to Joseph…was much closer than is the case with ordinary adoption. By the virgin birth the whole situation was raised beyond ordinary analogies. In an ordinary instance of adoption there is another human being—the actual father—who disputes with the father by adoption the paternal relation to the child. Such was not the case with Joseph in his relationship to Jesus, according to the New Testament narratives. He alone and no other human being could assume the rights and the duties of a father with respect to this child. And the child Jesus could be regarded as Joseph’s son and heir with a completeness of propriety which no ordinary adoptive relationship would involve.2
20 But as he considered these things, behold, an angel of the Lord appeared to him in a dream, saying, “Joseph, son of David, do not fear to take Mary as your wife, for that which is conceived in her is from the Holy Spirit.