Jesus’ mother Mary was “betrothed” to Joseph. Remember what “betrothal” was in the Jewish marriage process.* It consisted of two steps.
First, a formal marriage contract would worked out where a young man would be given marital and legal rights over a girl, usually when she was between twelve and thirteen years old.
During this time of betrothal, the boy and girl would be considered “husband and wife,” legally, but the girl would continue to live at her own family home, usually for about a year.
Second, after the year or so of betrothal, there would be a formal transfer or “taking of the bride” to the husband’s family home, and from that point on, he would be responsible for her support.
During the time of betrothal, no marital relations were tolerated: the wife had to be taken to her husband’s home as a virgin.
And it’s during that time, we’re told -- “When his mother Mary had been engaged to Joseph, but before they lived together” that she was found to be “having in the womb,” which is usually translated as “with child” or “pregnant.” And, we’re told, she is in that state “through a holy spirit.” (The Greek doesn’t refer to “the” Holy Spirit, but “a holy spirit” -- a God-given life breath and force by which the prophets speak.)
Joseph is an “upright,” “just” or “righteous” man, but unwilling to expose Mary to public disgrace.
Here’s his dilemma: Joseph would be considered an “upright man” not because of any special virtue he possessed, but because he is obedient to the Law. He blamelessly observes God’s commandments -- that’s what makes him upright. And according to the Bible (Deuteronomy 22:20-21), a young woman who is brought to her husband’s home and found not to be a virgin must be stoned.
But the Law also allowed a less severe option, which was divorce.
So because Joseph is obedient, he needs to find a way to be faithful to the Law, but because he is also merciful, he decides to proceed without accusing Mary publicly of adultery and subject her to a trial.
The key line in the passage, I think, comes next: “Just when he had resolved to do this…”
Just as he was considering this, just as he’s made his mind up, something happens.
An angel interrupts his plans and lifts him beyond his understanding, beyond his fears, into God’s dreams for him, Mary, and all of humanity.
*These insights indebted to Raymond E. Brown, The Birth of the Messiah