Hello this is quite interesting that you have asked this question because the story actually has modern day meaning. First Mary was a virgin, engaged woman, and a devout Judaism believer. Next, she is a pregnant overnight before she was married to Joseph. Hence an unwed mother situation, the couple were engaged but Mary was pregnant before they were “legally” accepted as married, Deuteronomy 24:1. The situation between the two revealed the personalities of both parents and tell us what kind of people they were. At the time of Mary's announcing to Joseph that she was pregnant the question of her spiritual value was upmost in Joseph’s mind, Matthew 1:19.
Another Issue is how Joseph responded to the information learned about Mary’s condition, both people were shown to be mature and able to start a family together. In the Bible it says that God himself intervene and approved of the union and helped out, Matthew 1:20-23. since it was expected that Joseph intended to "divorce" Mary as a means for addressing the issue and preferred spiritual purity at all costs. It also shows that both people handled their own problem among themselves without involving others which is wise and shows full ability to reason spiritually, Matthew 1:24-25.