What does this mean?
You must not give that which is holy to dogs. Do not cast your pearls before swine, or the swine may trample them under foot, and then turn on you and tear you to pieces.
In context, Jesus just taught his disciples not to judge in Matthew 7:1-5. The kind of judgment Jesus meant is the judgment of a critical and censorious spirit. That kind of judgment seeks to impute motivations to behaviors one person observes in another person. Since quite frequently, people have a tendency to project their own failings onto other people, Jesus had to teach his disciples that that kind of judgment is wrong.
On the other hand, there are times when Christians are to USE good judgment, particularly since they have a mandate to preach the gospel and make disciples. Times come, however, when the audience to our witnessing to the truth in Christ Jesus will confront us with hostility, hatred, and even occasionally violence. In situations such as those, Jesus does not expect us to continue being his witnesses to such hostile audiences.
The analogy Jesus uses is phrased in chiastic form (i.e., A-B-B-A, or A-B-B'-A', a form of inverted parallelism). In other words, in the form of a Miller's analogy, holy is to dogs which turn and tear you to pieces, as pearls are to swine who trample (i.e., holy:dogs that tear::pearls:swine that trample).
the dogs are analogous to people who are antagonistic to a disciple's witness for Jesus. Since dogs in Jesus' day were primarily of the wild, feral type, if you were to throw them a scrap of meat, they would eat the scrap, and when they had finished it they just might turn and attack the source of the meat! So it is with a person (or group of people) whose reaction to the gospel is not only antagonistic but even borders on being violent. From such a one, Jesus warned, steer clear.
the pigs are also analogous to people who are antagonistic to a disciple's witness for Jesus. Instead of expressing violence toward the Christian, they treat with contempt the pearls of wisdom they hear coming from the lips of Christians. A modern pig of this sort would be Bill Maher, who instead of "playing fair" when debating Christians will "fight dirty," calling the Christians names (the old ad hominem fallacy), making Christians' pearls of wisdom sound narrow-minded, old-fashioned, outmoded, outdated, stupid, idiotic, irrational, and on and on and on. Instead of debating issues intelligently, rationally, and fairly, he simply casts aspersions on people of faith.
Jesus used this kind of good judgment, for example, when his reading of Isaiah and his brief commentary on that reading in the synagogue in his home town caused his audience to be "filled with rage." Rather than letting the mob have their way with him--they wanted to throw Jesus to his death from the brow of the hill on which Nazareth was built, Jesus simply vanished!
"But passing through their midst, He went His way. And He came down to Capernaum, a city of Galilee, and He was teaching them on the Sabbath; and they were amazed at His teaching, for His message was with authority" (Luke 4:301-32).
What a difference between Jesus' audience in Nazareth and his audience in Capernaum! Matthew gives us some additional information about Jesus' experience in Nazareth:
"And they took offense at Him . . .. And He did not do many miracles there because of their unbelief" (13:57-58, excerpts).
Regarding these two kinds of audiences, the receptive audience and the hostile audience, Jesus told his disciples to use good judgment when they see they are getting nowhere with a hostile audience. That is, they are not to stick around and get into a harangue with an obviously hostile audience. Rather, they are to go to another audience who might be more receptive to the gospel of Christ.
Elsewhere in the Gospels, prior to sending his disciples out two by two, Jesus encouraged them to "shake the dust off their feet" as they left a town if the townspeople would neither receive them nor listen to what they had to say (see Matthew 10:14; Mark 6:11; and Luke 9:5).
In conclusion, judging people for their motives and for their faults as we see them, is the kind of judgment Christians are to avoid. On the other hand, using good judgment is the kind of judgment Christians (and churches, for that matter) are to use, whether in their interactions with unbelievers outside the church, or in their interactions with fellow believers within the church. The "sinners" outside the church, God will judge one day. The sinners inside the church, the leaders of the church are to judge, particularly is there are two or three witnesses to the sinful behavior of a brother or sister in Christ (see 1 Corinthians 5, especially verses 12 and 13).
The expression dogs in the gospels refers to those who are not Jews. So the disciples of Christ are not to give things which are holy or sacred to those who have no understanding of what a sacred thing is. It's the Jews that were educated by the Lord as to what was sacred. Pearls is used here as a precious thing that the wealthy understand and appreciate. No one would cast pearls before pigs. Because they .thinking that they are seeds would try to eat them and spitting them out would rush on the giver and trample him into the mud.