Wisdom is found using God's Holy Spirit. In order to gain this wisdom one must have knowledge and understanding. That kind of understanding can only come through God's Holy Spirit which is given to those who obey Him. (Acts 5:32)
How do we gain this understanding which can lead us to that pearl of great price?
"Through thy precepts I get understanding: therefore I hate every false way." (Psalm 119:104)
God's precepts are written in the Holy Scriptures. If one has God's Holy Spirit, one can study God's Word (His Precepts) for Holy knowledge, and upon this foundation of the Holy Spirit and Holy knowledge, God will then grant Holy understanding.
This "pearl" then is the knowledge and understanding of God's pure truth given to a person through God's Holy Spirit.
If we take that pearl (of wisdom) and cast it (meaning to throw it away without caring where it falls) before "dogs" (a metaphor for someone with an impure or impudent mind) or "swine" (something or someone who is unclean), Jesus warns us that they might "tear you into pieces" (they might distort what we are saying and might even attack us.)
God tells us in the book of Proverbs that there are times when we should be silent and times when we should respond directly to others (especially about God's truth). Jesus sometimes answered the questions and accusations thrown his way by the religious leaders of his day (e.g. Matthew 12:1-8) and sometimes refused to respond to their inquiries (e.g. Matthew 21:23-27). Proverbs states:
"Do not answer a fool according to his folly, lest you also be like him.
"Answer a fool according to his folly, lest he be wise in his own eyes." (Proverbs 26:4-5)
We must discern the reason for any questions according to the person who is doing the asking and answer within that context.
We should not cast our pearls of Godly wisdom before one who is a militant, ready to fight, unbeliever lest they turn on us and insult us or do us harm.
Thank you for submitting your question about why we should not cast PEARLS before SWINE.