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.
The original prophecy has a dual application. The first to a child (possibly Hezekiah) at the time of Isaiah, so it does not refer to a literal virgin birth in the first application. We know the birth of Jesus was a literal virgin birth not from Isaiah, but from the words of Mary, Joseph and the angel Gabriel recorded in the Gospels of Matthew and Luke.
“How can this be,” Mary asked the angel, “since I am a virgin?” 35 The angel replied, “The Holy Spirit will come upon you, and the power of the Most High will overshadow you. So the Holy One to be born will be called the Son of God. (Luke 1:34-35)
Jesus being born to a virgin, is descended from David through his mother Mary, whose family tree is found in Luke, not Matthew, 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 descendant 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.
The curse on the line of Jeconiah
Another reason why Jesus would be physically descended from David via Solomon’s brother Nathan (ancestor of Heli, Mary’s father) and not from Solomon’s line is that according to the legal genealogy from Solomon in Matthew 1:12, Jesus is a descendant of Jeconiah. But Jeconiah was cursed in Jeremiah 22:24 and 22:30 that no descendant of his would be king. This effectively cut off the line from Solomon. However legally, as adopted son of Joseph, Jesus is still a legal descendant of Solomon, though physically from Nathan Solomon’s brother (see the genealogy of Mary in Luke Chapter 3).