The question continues:
Is there a spiritual connection or reason for this instead of his lineage of David coming through his father Joseph?
Reasons why God brought Jesus into the lineage of David through Mary
We know that the Messiah was to be descended from David – 2 Samuel 7:12-14:
When your days are fulfilled and you lie down with your fathers, I will raise up your offspring after you, who shall come from your body, and I will establish his kingdom. (13) He shall build a house for my name, and I will establish the throne of his kingdom forever. (14) I will be to him a father, and he shall be to me a son. . . .
And we know that this Messiah was to be born to a virgin. Isaiah 7:14:
Therefore the Lord himself will give you a sign. Behold, the virgin shall conceive and bear a son, and shall call his name Immanuel.
Jesus being born to a virgin, is descended from David through his mother Mary but not through a man.
Spiritual reason for Jesus being the son of Mary not the son of Joseph
Joseph was Jesus’ adoptive father not his real father, although as Luke 3:23 points out, Joseph was supposed, by the people, to be Jesus’ father. It is commonly thought that the Luke genealogy of Jesus goes through his adoptive father, Joseph and the Matthew genealogy goes through his mother Mary.
Jesus is the focus of the creation of the universe and more specifically the earth. Colossians 1:16-17 LITV:
For all things were created in Him, the things in the heavens, and the things on the earth, the visible and the invisible; whether thrones, or lordships, or rulers, or authorities, all things have been created through Him and for Him. (17) And He is before all things, and all things have subsisted in Him.
Although God created everything for Jesus, Jesus was the way that those chosen from the foundation of the world (Ephesians 1:4) , would be saved. Jesus had an incredibly difficult job to do. God planned the way that salvation would come to people and this way is not possible without God and Jesus. Man cannot save himself. He has to rely on God and Jesus. Just as the chosen are called by God and born anew, to a much greater degree Jesus was born not of the will of the flesh nor of the will of man, but of God. See John 1:12-14:
But to all who did receive him, who believed in his name, he gave the right to become children of God, (13) who were born, not of blood nor of the will of the flesh nor of the will of man, but of God. (14) And the Word became flesh and dwelt among us, and we have seen his glory, glory as of the only Son from the Father, full of grace and truth.
The virgin birth shows that the Messiah was born of God according to God’s will not man’s will. It is also a fulfillment of God’s promise to Eve that her descendent would destroy the serpent and the seed of the serpent (sin) Genesis 3:15, thereby preparing the way for salvation of mankind from his fallen state.