This is a messianic promise of God to David. God promised that the Messiah, the King of Israel, would be David's descendant. David's son, Solomon, ruled all of Israel. However after the death of Solomon, when the nation divided into the ten and two tribe kingdoms, David’s grandchildren ruled only the kingdom of Judah. Why maintain the crown through Judah? Much earlier, in the book of Genesis, the tribe of Judah was initially promised the lineage of Messiah.“The scepter will not depart from Judah, nor the ruler’s staff from his descendants, until the coming of the one to whom it belongs, the one whom all nations will honor.” (Genesis 49:10, New Living Translation) Thus, Messiah was to come from the tribe of Judah and from the specific Judean family of David.
The ruling authority over Israel was given to the Davidic line by God himself, when he directed Samuel the prophet to anoint David and reject the lineage of the first king of Israel, Saul. Israel's ancient history is graphically outlined in the Old Testament and establishes the expectation that the great ruler of Israel and the world, Messiah would be recognized because of his relationship to King David.
This prophetic reference to Messiah was fulfilled in Jesus, because his lineage through his mother, Mary, as well as his legal genealogy through Joseph traced back to David. Matthew 1:1-17 gives the legal line through Joseph and the Luke account most likely delineates the line through Mary. Thus, Jesus was from the Davidic line through his mother and also legally, through the line of his legal father, Joseph.