Deuteronomy 22:
16 The young woman’s father must say to the elders, “I gave my daughter to this man and he has rejected her. 17 Moreover, he has raised accusations of impropriety by saying, ‘I discovered your daughter was not a virgin,’ but this is the evidence of my daughter’s virginity!” The cloth must then be spread out before the city’s elders. 18 The elders of that city must then seize the man and punish him. 19 They will fine him 100 shekels of silver and give them to the young woman’s father, for the man who made the accusation ruined the reputation of an Israelite virgin. She will then become his wife, and he may never divorce her as long as he lives. 20 But if the accusation is true and the young woman was not a virgin, 21 the men of her city must bring the young woman to the door of her father’s house and stone her to death, for she has done a disgraceful thing in Israel by behaving like a prostitute while living in her father’s house. In this way you will purge the evil from among you.
Matthew 1:19
18 Now the birth of Jesus Christ happened this way. While his mother Mary was engaged to Joseph, but before they came together, she was found to be pregnant through the Holy Spirit. 19 Because Joseph, her husband to be, was a righteous man, and because he did not want to disgrace her, he intended to divorce her privately. 20 When he had contemplated this, an angel of the Lord appeared to him in a dream and said, “Joseph, son of David, do not be afraid to take Mary as your wife because the child conceived in her is from the Holy Spirit.
Protoevangelium of James 14
Gospel of James14 Joseph was deeply afraid and withdrew from Mary, thinking about what he should do. He said to himself, “If I cover up her supposed sin, I will be going against the law of the Lord; but if I expose her to the people of Israel, I fear that what’s inside her might be from an angel, and I’ll be responsible for condemning innocent blood to death. What should I do? I’ll quietly divorce her.” As night fell, an angel of the Lord appeared to him in a dream, saying, “Don’t be afraid to take Mary as your wife, for what’s conceived in her is from the Holy Spirit. She will give birth to a Son, and you will name Him Jesus, for He will save His people from their sins.” Joseph woke from his dream, glorifying the God of Israel for the grace he had been given, and he stayed with Mary.
Notes and References
"... The Matthean materials interrupt the original sequence of the narrative in The Protevangelium of James 14:01a and continue to the end of chapter 14. An intermediary passage occurs between Protevangelium 14:01b and the close parallels with Matthew that begin at Protoevangelium 14:04b. Protoevangelium 14:01b-04a represents an expansion of Matthew 1:19, in which Joseph has made his decision to put Mary away in secret immediately after she was found pregnant in Matthew 1:18. But in Protoevangelium 14:01b-04a, Joseph engages in an internal dialogue considering what he should do about Mary. Joseph pondered two options. In Protoevangelium 14:02, he considered the risk that if he hid her sin, he would violate the law of the Lord. (Compare the marriage laws in Deuteronomy 22:13-30 according to which Mary would be guilty of a capital offense and would be stoned to death.) In Protoevangelium 14:03, he thought of exposing her but feared that if her child was of “angelic” origin, he would be guilty of betraying innocent blood to a judgment of death ..."
Zervos, George The Protevangelium of James: Greek Text and English Translation with a Critical Introduction (Volume 1) (p. 64) T&T Clark, 2019