Jesus said these words twice, and both times he said them to protect someone.
The dinner party
There was a man named Matthew who collected taxes for the Romans who ruled the land. People hated tax collectors. They took money from their own neighbors, often more than they should, and gave it to the people in charge.
Jesus walked past Matthew's tax booth and said, "Follow me." Matthew got up and went.
Soon after, Jesus was having dinner at a house with Matthew and a lot of other tax collectors, and people everyone called sinners. Some Pharisees saw it. They were members of a religious movement that cared deeply about living by the law. They asked his followers why their teacher would eat with people like that.
What Jesus said
Jesus heard them. He said that healthy people do not need a doctor. Sick people do. Then he quoted Hosea, a prophet who spoke for God hundreds of years before.
But go ye and learn what that meaneth, I will have mercy, and not sacrifice: for I am not come to call the righteous, but sinners to repentance.
Matthew 9:13 · King James VersionThe original Greek
πορευθέντες δὲ μάθετε τί ἐστιν· Ἔλεος θέλω καὶ οὐ θυσίαν· οὐ γὰρ ἦλθον καλέσαι δικαίους ἀλλὰ ἁμαρτωλούς.
Found in Codex Vaticanus (about AD 325), Codex Sinaiticus (about AD 350).
The words "to repentance" appear in later copies, not in the oldest ones.
In those days, a sacrifice was an offering at the temple. It was the religious thing to do. Jesus was saying God wanted something else more. He wanted kindness to the people in front of you.
The second time
Later, Jesus's hungry followers picked some grain to eat while walking through a field on the Sabbath, the weekly day of rest. Some Pharisees said they were breaking the rules. Jesus quoted the same words again. If they had understood mercy, he said, they would not have blamed people who were innocent.
What it means for us
Both times, someone was being judged by religious people. Both times, Jesus stood in front of them and said mercy comes first.
We can fall into the same thing. It is easy to care more about doing church right than about the person sitting alone in the back. Jesus's words are a gentle way back. God cares about rituals far less than he cares about how we treat each other. If you have ever been the one sitting alone in the back, he was talking about you too. He would have pulled up a chair for you at that dinner. He is kind to you first.