It comes from Luke 10:25-37. Here’s the full passage from the NIV translation of the Bible.
On one occasion an expert in the law stood up to test Jesus. “Teacher,” he asked, “what must I do to inherit eternal life?”
“What is written in the Law?” he replied. “How do you read it?”
He answered, “‘Love the Lord your God with all your heart and with all your soul and with all your strength and with all your mind’[a]; and, ‘Love your neighbor as yourself.’”
“You have answered correctly,” Jesus replied. “Do this and you will live.”
But he wanted to justify himself, so he asked Jesus, “And who is my neighbor?”
In reply Jesus said: “A man was going down from Jerusalem to Jericho, when he was attacked by robbers. They stripped him of his clothes, beat him and went away, leaving him half dead. A priest happened to be going down the same road, and when he saw the man, he passed by on the other side. So too, a Levite, when he came to the place and saw him, passed by on the other side. But a Samaritan, as he traveled, came where the man was; and when he saw him, he took pity on him. He went to him and bandaged his wounds, pouring on oil and wine. Then he put the man on his own donkey, brought him to an inn and took care of him. The next day he took out two denarii and gave them to the innkeeper. ‘Look after him,’ he said, ‘and when I return, I will reimburse you for any extra expense you may have.’
“Which of these three do you think was a neighbor to the man who fell into the hands of robbers?”
The expert in the law replied, “The one who had mercy on him.”
Jesus told him, “Go and do likewise.”
The thing that’s lost in modern readings is, who exactly is a Samaritan? In Jesus’ time the Samaritans were both an ethnicity and a religion. The Samaritans were closely related to the Jewish people and also worshiped YHWH. But they believed that the Jewish version of the religion had been corrupted during the Jewish captivity in Babylon. I won’t go into the differences but needless to say they considered each other heretics. The Samaritans lived in Samaria, map here, basically the area of central Israel/Palestine between Galilee and Jerusalem.
The story is the rough equivalent of a Catholic priest praising a Protestant at the height of Europe’s religious wars. If we imagine this theoretical retelling the men passing the injured man by might be a bishop and a monk. While the Samaritan might be a Lutheran or Anabaptist. It’s a story of goodness coming from a particularly hated outsider group.
As an aside the fact that the Priest and Levite passed by shouldn’t necessarily be seen as a moral failing. Both men would have been made ritually impure by touching the wounded man had he died. As such in their period of ritual impurity would have interfered with their religious duties. So while not praiseworthy, there’s not innately a condemnation of them for not rendering aid.