Matthew 1
Matthew lists the genealogy of Jesus which includes Ruth and includes the statement that Solomon’s mother had been the wife of Uriah the Hittite.
The genealogy is a quick way to recite all the history contained in the Old Testament from Abraham. The readers at that time would know all the names and their stories.
The four women mentioned in this genealogy all have ties to gentiles. Three were gentiles that married into Israel and Bathsheba was an Israelite that married a Hittite before she married David.
Matthew 1:19 NIV
[19] Because Joseph her husband was faithful to the law, and yet did not want to expose her to public disgrace, he had in mind to divorce her quietly.
Joseph could have divorced her publicly but did not want to make it public.
By marrying her Joseph adopted the child and gave him a birthright and heritage but also adopted the shame of Mary being pregnant before marriage.