Sometimes readers, are somewhat puzzled by the Gospel's affirmation that Joseph was a just man, and he decided to divorce Mary.
If he really was a just man, then he should have been more trusting towards Mary. Given his time's religious and consequent social culture, he would naturally have felt that "divorcing" Mary from any obligations arising from their betrothal was kinder towards her than any other way which would have meant making the situation public.
Some biblical scholars would see the matter differently. The key to a deeper understanding would lie in the meaning of the word "just" in the Bible. It primarily refers to God, for as Jesus reminds us "only one is good" (Lk.18:19). Therefore, all human social justice derives from God's justice.
So, if Joseph was a just man, he was close to God and sensitive to God being present and working in the world. God was also working in Mary's life.
As a just man, he felt that he should withdraw from her life and not interfere with God's work in her life, whatever it might be. Of course, there is no way to prove this interpretation, but it does make good theological sense.
Father in heaven, when we do not understand Your way of working in our lives, give us the grace of humility to cooperate with You in all things and so find peace in Your love.