I find this a very insightful question mostly because people don't often associate casting pearls before swine as a potentially dangerous activity. It's mostly just seen as a waste of time. But check out the warning of danger issued by our Lord:
“Do not give dogs what is holy, and do not throw your pearls before pigs, lest they trample them underfoot AND TURN AND ATTACK YOU." Matthew 7:6 (ESV my emphasis)
It's truly amazing how many Christians ignore those last five words, but there's an unmistakable warning in this verse. Let's see if we can unpack it a little and discover where that danger comes from.
Do not give dogs what is holy, and do not throw your pearls before pigs...
Immediately before this verse, Jesus had been talking about not being critical and judgmental of others. But with this verse we're reminded that we can't throw out discernment altogether. Frankly, there are some precious spiritual truths that should not be given to those who will only receive them with derision and contempt. Just as a dog or a pig has absolutely no appreciation for the value of a pearl, there are some people who place no value on God's Word or His promises.
...lest they trample them underfoot and turn and attack you.
Dogs and swine were considered filthy and useless in ancient Jewish society. Pigs were unclean under the Mosaic Law, and wild dogs ran in packs, rummaging through garbage and even attacking people on occasion. Therefore it's not hard to see how the reference to dogs and swine in the Matthew passage would point to those hostile to the Kingdom of God and the Good News that we share. And whenever there is a hardened rejection of God's message, there will always be the possibility of God's people suffering some kinds of personal attack.
Matthew 7:6, therefore, calls us to walk in a level of discernment concerning those with whom we share the spiritual realities of the Lord. It behooves all believers to ask God for a heightened understanding concerning those we should and shouldn't approach.