Why was Joseph the descendent of David that links Jesus lineage to the Davidic line and not Mary?

Why wouldn’t God choose a woman who was of the lineage of David rather than Joseph who shares no DNA with Jesus?