Jesus made his point by using dogs and pigs, both unclean animals to the Jews. A portion of the holy sacrifice was eaten by the priest. Pearls are totally without value to pigs, though they were extremely valuable to those people. Since pearls are not food to pigs, pigs will sniff at then ignore a pearl, and then trample it into the muck of the pig pen. If you frustrate or disappoint the dog or the pig, they will turn on you and rip you if they can.
Some people are incapable of understanding what is holy and what is spiritually of great value.
They not only have no appreciation of what you try to share with them, but they easily become irritated and frustrated with you. Among the most violent enemies you will ever encounter are religious enemies. Some of the most horrible things are done in the name of religion. Jesus was talking about both ungodly and religious people who were incapable of appreciating his teachings. When a person understood Jesus' teachings, that understanding makes him aware of how much he does not know, does not understand.