Answer
There are three passages of Scripture that pertain specifically to the time of Joseph and Mary’s betrothal, the consummation of their marriage, and the birth of Jesus: Matthew 1:18-25; Luke 1:26-56; Luke 2:1-7. Each passage reveals something about their relationship as well as the cultural mores of that time.
In Bible times, Jewish marriage customs regarding a couple’s engagement were far different and much more stringent than those we are familiar with today, especially in the West. Marriages were arranged by the parents of the bride and groom and often without even consulting the couple to be married. A contract was prepared in which the groom’s parents paid a bride price. Such a contract was immediately deemed binding, with the couple considered married even though the actual ceremony and consummation of the marriage would not occur for as long as a year afterwards. The time between was a sort of testing of fidelity with the couple having little, if any, contact with each other.
It was during this betrothal period that the angel Gabriel visited Mary and told her of her impending pregnancy. It’s no small wonder that Mary was so inquisitive of the angel; she was still a virgin and would know no man sexually for several months, maybe as long as a year or more (Matthew 1:18; Luke 1:34).
Joseph soon became aware of Mary’s pregnancy, and this no doubt was cause for consternation on his part: “Because Joseph her husband was a righteous man and did not want to expose her to public disgrace, he had in mind to divorce her quietly” (Matthew 1:19). Jewish custom allowed that they be considered as husband and wife, though the marriage had not yet been consummated. The point is being made that Joseph and Mary had experienced no sexual contact with each other, as verse 18 “before they came together” points out. So, Joseph was in a quandary. Jewish law provided that his betrothed, because of her unfaithfulness, could be placed before the elders for judgment and stoned to death. But he was thinking to just put her away quietly without public knowledge. Betrothals or marriage engagements in those ancient times were binding and could only be terminated by an official divorce decree.
It was then that the angel appeared to Joseph in a dream (Matthew 1:20-25) and explained to him that all this was bringing about the fulfillment of prophecy that a virgin would bear a child who was to be the Savior (Isaiah 7:14), and “he [Joseph] did what the angel of the Lord had commanded him and took Mary home as his wife. But he had no union with her until she gave birth to a son. And he gave him the name Jesus.”
Luke 2:1-7 also confirms the idea that Joseph and Mary, though betrothed, were considered as husband and wife by Jewish customs even though the actual marriage ceremony had not been fully effectuated. So, Joseph and Mary were actually legally married before the birth of Jesus though their marriage was not consummated physically until after His birth.