The passage in question occurs in Matthew 15:21-28. Our Lord is approached by a gentile Canaanite woman (also called the Syro-Phoenician woman) whose daughter is possessed by a demon. On first hearing their conversation, Our Lord definitely seems hostile and uncompassionate; however, to draw such a conclusion is contrary to who Jesus is.
This passage is indeed complicated. Understanding the cultural context will help. First, Jesus’ mission was first to the people of the covenant, i.e., the Jews, who were awaiting the Messiah. Technically, the mission to the gentiles was not granted until the Ascension, when Our Lord said, “Go out and make disciples of all the nations” (Mt 28:18-20). Nevertheless, He already had shown His openness to the gentiles, like curing the centurion’s serving boy (Mt 8:5-13).
Second, Jews considered gentiles as “dogs.” To call a person a “dog” was a severe insult. The Jews used phrases like, “gentile dog,” “infidel dog” and later, “Christian dog.” However, Jesus used the diminutive form for “dog,” better translated as “puppy.” So instead of calling her the insulting “junk yard dog,” He calls her “lovable puppy.” (Keep in mind the English translation misses this distinction from the original Greek text.)
One would also have to ponder about how Jesus said this phrase. He must not have said “dog” with contempt or scorn. Rather, He probably said it tongue-in-cheek. For instance, to call someone a “rascal” literally would be derogatory, but I remember calling my nephew (when he was a toddler) “you little rascal,” of course in a loving way. Our Lord may even have been criticizing the normal Jewish parlance.
What is most important is the woman’s faith and her perseverance: “Oh woman, great is your faith! Let it be done for you as you desire.” So in the end, Our Lord praises the gentile “dog” for faith and perseverance that surpassed the Jews.