The issue of Jesus’ father was problematic for his attempt to be recognized as Messiah – just as it was for his parents before he was born.
Mary is described by a word which can mean either ‘virgin’ or ‘girl of marriageable age’ – but strongly carries a meaning of ‘not married’.
The Gospels state that Joseph discovered that Mary was already pregnant when he married her, and, being a just man, decided to divorce her quietly rather than make a public example of her. But, after dreams changed his mind, he chose another reasonable solution: go to a different town (Bethlehem, where his own family was from) for a few months, let her have the baby where no one knew when they had married, and then return home (Nazareth) where no one knew when the baby had been born. That way the fiction of Jesus’ legitimacy could be maintained.

Stoning people to death for sexual misconduct is an ongoing tradition of monotheism
It was important for a child to have been conceived within marriage. Even if the parents subsequently married, if the child was conceived outside marriage it was considered a bastard. The laws in Deuteronomy are clear and harsh:
- married woman has sex with another man, both stoned to death
- betrothed virgin raped in a town, both stoned to death (she, for not having called for help)
- betrothed virgin raped in the countryside, only the man stoned to death
- unbetrothed virgin raped, the rapist has to pay the victim’s father fifty silver shekels and marry her.
So, depending on quite how young Mary got pregnant, her life was in danger. Assume Joseph loved her – he needed to be creative to protect her.
The problems of illegitimacy came up again when Jesus was making his play for Messiah and King. As Deuteronomy 23:2 states: “A bastard shall not enter into the congregation of the LORD; even to his tenth generation shall he not enter into the congregation of the LORD.”
Not surprising, then, that his followers grasped at whatever unlikely explanations they could think of, in order to explain away the embarrassing rumors!