Some Pharisees saw them do it and protested, "Your disciples shouldn't be doing that! It's against the law to work by harvesting grain on the Sabbath."
But Jesus said to them, "Haven't you ever read in the Scriptures what King David did when he and his companions were hungry?
He went into the house of God, and they ate the special bread reserved for the priests alone. That was breaking the law, too.
And haven't you ever read in the law of Moses that the priests on duty in the Temple may work on the Sabbath?
I tell you, there is one here who is even greater than the Temple!
But you would not have condemned those who aren't guilty if you knew the meaning of this Scripture: 'I want you to be merciful; I don't want your sacrifices.'
References for Matthew 12:7
For I, the Son of Man, am master even of the Sabbath."
Then he went over to the synagogue,
where he noticed a man with a deformed hand. The Pharisees asked Jesus, "Is it legal to work by healing on the Sabbath day?" (They were, of course, hoping he would say yes, so they could bring charges against him.)
And he answered, "If you had one sheep, and it fell into a well on the Sabbath, wouldn't you get to work and pull it out? Of course you would.
And how much more valuable is a person than a sheep! Yes, it is right to do good on the Sabbath."