Whereupon Joseph her husband, being a just man, and not willing publicly to expose her, was minded to put her away privately.
“And when she was twelve years old there was held a council of priests, saying, ‘Behold, Mary has reached the age of twelve years in the temple of the Lord. What then shall we do with her, lest perchance she defile the sanctuary of the Lord?’ And they said to the high priest, ‘You stand by the altar of the Lord; go in and pray concerning her, and whatever the Lord shall manifest to you, that also will we do.’ . . . [A]nd he prayed concerning her, and behold, an angel of the Lord stood by him saying, ‘Zechariah! Zechariah! Go out and assemble the widowers of the people and let them bring each his rod, and to whomsoever the Lord shall show a sign, his wife shall she be. . . . And Joseph [was chosen]. . . . And the priest said to Joseph, ‘You have been chosen by lot to take into your keeping the Virgin of the Lord.’ But Joseph refused, saying, ‘I have children, and I am an old man, and she is a young girl’” (ibid., 8–9).
“And Annas the scribe came to him [Joseph] . . . and saw that Mary was with child. And he ran away to the priest and said to him, ‘Joseph, whom you did vouch for, has committed a grievous crime.’ And the priest said, ‘How so?’ And he said, ‘He has defiled the virgin whom he received out of the temple of the Lord and has married her by stealth’” (Protoevangelium of James., 15).
“And the priest said, ‘Mary, why have you done this? And why have you brought your soul low and forgotten the Lord your God?’ . . . And she wept bitterly saying, ‘As the Lord my God lives, I am pure before him, and know not man’” (ibid.).
So, the Gospel implies that Joseph’s secret divorce from Mary might protect Her from being exposed. While the Protoevangelium says She was a consecrated virgin, so everyone knew She was supposed to be chaste. And Her divorce from Joseph might only have made the things worse for Her, as She would have had no witness to testify in her defense.
Of course, I know that Protoevangelium is not a canonical book, but still…