1) It is clear from verse 19 that Joseph's righteousness (with respect to the Mosaic Law) was the reason and impulse behind his decision to divorce her quietly. This was truly (according to Jesus) the only "matter of uncleanness" that was honestly a part of the Law (Lev. 24:1). All else was fabrication.
2) That he was "unwilling to make her a public spectacle" would have had direct relevance to the duty of the community to stone a lewd woman to death (Lev. 22:21, see from v. 13-27); Roman Law notwithstanding, such was God's directive. A couple conclusions follow: a) a pregnant woman in any case would probably never be executed at all given her duty to the baby, almost certainly not before the birth; b) victims (Joseph in this case, according to the outward appearance) had rights and privileges under the Law, which they were not under obligation to demand any or all of; c) Mary would have been disgraced in any case, no matter what happened, and probably never married. I think the woman-at-the-well is an example of a genuinely worldly woman who probably started off in some kind of disgrace herself.
3) The very existence of the divorce regulation implies that the statute for stoning adulterers was not absolutely rigid, with no room for mercy. This is in addition to the difficulty of ensuring two or three witnesses to the capital crime. The accusation of adultery could obviously be brought by either an offended party (husband/wife) or a third party. The statement in Lev. 20:10, "shall surely be put to death" is very strong and absolute, but we must ask why?
It is because the deed must be clearly defined as one worthy of death, and thus the default position. In this it is like the command (Ex. 21:12) "He that smiteth a man so that he die, he shall surely be put to death." But that is immediately followed by the provision for manslaughter. Thus the pronouncement is a general one, the default position, to which different mitigations are introduced, and may which change the outcome
There is also the matter of the party bringing the case. If a third party brings the case, rather than an offended husband or wife, then there is little or no room for mercy. The magistrate is bound to the Law. If the judge grants leniency (divorce) on his own authority, then he risks offending God, who demanded the adulterers' deaths. Perhaps a Judge, Prophet, High Priest, or later the King could pardon (literally in God's name), but otherwise, all were bound to the Law.
How about in the case of husband or wife bringing suit? Ideally, confession of sin would bring repentance, and repentance would bring forgiveness, even the restoration of the covenant of marriage. But, as Jesus pointed out, hardness of heart--either unrepentedness or unforgiveness--often made divorce the next option, but before death. Thus, the original provision of divorce (as regulated) was chiefly an option of mercy.
A wounded husband or wife had the right to demand the adulterer's death. But perhaps the victim would not call for the perpetrator's death. Maybe some remnant of feeling for them, but going back into marriage covenant was not desireable either. Thus, when the victim brings his case to the court, it is either a divorce case, or it is a capital case.
Joseph was Law-observant. He was not going to complete the engagement with Mary, but he also did not desire her death. She appeared to be "unclean" by adultery (pregnant). Being kindly disposed toward her, nonetheless, he planned to divorce her as quietly as possible, and move on. God intervened.