In the genealogy Matthew names 5 female ancestors of Jesus, the first 3 were Gentiles and the fourth was married to a Gentile. Why would this have been important for Matthew’s community?
Matthew's book portrays Jesus Christ with regard to a particular aspect. The book has a purpose and its content reflects that purpose. The kingdom of heaven features particularly strongly in the pages of Matthew as do the several parables describing the kingdom of heaven being 'like' or 'likened to' something that is less than what is outwardly apparent.
The book is a matter of contrasts, as are the parables of the kingdom which contrast that which is inherently spiritual against that which is outwardly more (apparently) glorious.
The genealogy which Matthew records is the royal line of succession and features the omissions that are a result of God's judgements on the kings of Judah.
But among the ancestors recorded, there stands out Tamar the Canaanite, Rahab the harlot of Jericho, Ruth the Moabitess, and Urijah the Hittite.
Yes, gentiles, in the providence and wisdom of God who is not willing that any should perish but that all should come to a knowledge of the truth.
Right from his opening page, Matthew is declaring that God's purposes never were restricted to one nation - albeit he, himself, favoured that nation in order to proclaim something on earth to all the nations.
The remarkable stories of Tamar, Rahab and Ruth stand out in the genealogy, along with the reminders - in the kings - of the terrible failures of Israel to live up to their inestimable privilege.
Then, increasingly, Matthew - by specifically recording certain items, chosen parables, distinct events - weaves a narrative that displays the purpose of God to be heavenly, not earthly, to be for an entire world (to come) not just one nation, to be for ever (not just the duration of a natural kingdom on earth).
The climax, after the events of the crucifixion of Jesus and his resurrection from the dead, is the sending forth of the eleven to the whole earth, to every creature under heaven - to teach all nations :
Go ye therefore, and teach all nations, baptizing them in the name of the Father, and of the Son, and of the Holy Ghost: Matthew 28:19 KJV.
The significance of the women mentioned is their origin and it is not Bathsheba that is mentioned but Urijah and his Hittite origin that is drawn attention to.
They are specifically mentioned because of their individual (and remarkable) stories as they were brought in within the skirts of Israel, despite being of gentile origin - as would be gathered multitudes from the nations to join - as one - with those of Jewish origin to form one church.