At some point in my studies I recall a discussion about how Mary and Joseph were spiritual persons who would have been very familiar with Jewish religious traditions and practices.
They were told that what was growing in Mary’s womb was holy. (Matthew 1:20)
They would have understood that the protocols that were involved with being ceremonially clean when coming into the holy place (temple) would be fitting for one favored to carry the holiest of God’s possessions, his son, inside her body.
For this reason Mary would have felt it necessary, even mandatory, to maintain herself ritually clean to the fullest extent possible.
The Law given to Moses spelled out certain protocols that had to be followed by persons who were going to temple. Among these was the command that when a couple engaged in sexual activity, they were ceremonially unclean. They were to wash and would not be clean until the evening.
Leviticus 15:18 (NWT)
When a man lies with a woman and has an emission of semen, they should bathe in water and be unclean until the evening.
Knowing this and fully aware that for 9 months she was in effect the bearer of the holiest utensil of God’s temple, Mary would have indeed seen the necessity to refrain from sexual relations with her husband.
Expanding on this school of thought Peter Leithart wrote:
He Did Not Know Her
Joseph did not know his wife until she gave birth to a Son (Matthew 1:25). Why not?
In Matthew’s account, the conception of Jesus is attributed to the “Holy Spirit” (1:20), and Luke makes it explicit that the one conceived by the Holy Spirit is Himself holy: “the holy thing begotten shall be called the Son of God” (Luke 1:35).
Joseph might have reasoned: Since Mary was inhabited by the Spirit, and by the Holy One conceived by the Spirit, she was, or at least her womb was, holy space. If she is holy space, he cannot have sex with her, since by the rules of Torah sex defiled both the man and the woman (Leviticus 15:18). Having sex with Mary during her pregnancy would have been like a leper or a menstruant entering the temple of God. It would have been like having sex in the temple court itself.
If this is the reasoning, it sheds some light on the question of perpetual virginity. Matthew’s phrasing implies that Joseph did have sex with Mary after Jesus was born, and the reasoning above would imply the same. Temples are holy only when the Holy One inhabits them. Once Yahweh abandoned the temple, it was an empty shell for demolition and burning. If Mary was holy because the Holy One lived in her, then His birth exodus from her body would have ended her temporary holiness. She would have reverted to normal “common” status. And Joseph would have known her as his wife.
Joseph refrained from sex with Mary because she was the ark, bearing the glory; but only for nine months.
This article by Leithart captures much of what I recall as to why it was necessary for Mary to remain a virgin during the entire course of her pregnancy.