“Now it happened that He went through the grainfields on the Sabbath; and as they went His disciples began to pluck the heads of grain. And the Pharisees said to Him, ‘Look, why do they do what is not lawful on the Sabbath?’ But He said to them, ‘Have you never read what David did when he was in need and hungry, he and those with him: how he went into the house of God in the days of Abiathar the high priest, and ate the showbread, which is not lawful to eat except for the priests, and also gave some to those who were with him?’ And He said to them, ‘The Sabbath was made for man, and not man for the Sabbath.’”
The Sabbath day is the seventh day of the week, starting on Friday at sundown and continuing until Saturday at sundown. It was established by God for the primary purpose of abstinence from work, i.e., rest (Exodus 20:8-11):
“Remember the Sabbath day, to keep it holy. Six days you shall labor and do all your work, but the seventh day is the Sabbath of the LORD your God. In it you shall do no work: you, nor your son, nor your daughter, nor your male servant, nor your female servant, nor your cattle, nor your stranger who is within your gates. For in six days the LORD made the heavens and the earth, the sea, and all that is in them, and rested the seventh day. Therefore the LORD blessed the Sabbath day and hallowed it.”
In Mark 2:27 Jesus declared that “The Sabbath was made for man, and not man for the Sabbath.” That is, just as God created people, God established the Sabbath for the benefit of people, especially those who follow Him.
Under the (now broken) old covenant given to and through Moses, violation of the Sabbath ordinance was punishable by death (Exodus 35:1-3; Numbers 15:32-36). Consequently, in Mark 2:23-27, when the Pharisees observed Jesus’ (obviously hungry) disciples plucking heads of grain, they said to Jesus:
“Look, why do they do what is not lawful on the Sabbath?”
That is, the Pharisees perceived the picking of grain by these hungry sojourners as a form of work and thus a violation of the Sabbath law. This is to a degree understandable, for when God provided manna to the Israelites in the wilderness ~1500 years earlier, He commanded them to gather twice as much as was needed on the sixth day and to refrain from attempting to collect or cook manna on the seventh day of the week in order that they would observe the Sabbath (Exodus 16:4-5; 22-26).
However, Jesus rebuked the Pharisees and their understanding of Scripture through reference to another passage, 1 Samuel 21:1-6:
“He said to them, ‘Have you never read what David did when he was in need and hungry, he and those with him: how he went into the house of God in the days of Abiathar  the high priest, and ate the showbread, which is not lawful to eat except for the priests, and also gave some to those who were with him?’”
Through this incident, Jesus was effectively teaching that the ceremonial law which forbade the consumption of the showbread by anyone other than a priest (Leviticus 24:9) is superceded by a spiritual law : provision of food for the needy (Leviticus 23:22):
“When you reap the harvest of your land, moreover, you shall not reap to the very corners of your field nor gather the gleaning of your harvest; you are to leave them for the needy and the alien. I am the LORD your God.”
Jesus declared that (1) just as David and his followers were hungry and in need of food, He and His disciples were hungry and in need of food, and that (2) just as David and his followers ate the consecrated showbread without any apparent objection from God, it was also acceptable to God for Jesus and His disciples to pluck heads of grain which had likely been left in the field by the owner of the field for that very purpose.
This is an excellent reminder that the new covenant has replaced the old covenant; don’t get hung-up on ceremonial regulations, but discern and apply underlying spiritual truths. As Jesus once said to the Pharisees (Matthew 23:23):
“Woe to you, teachers of the law and Pharisees, you hypocrites! You give a tenth of your spices—mint, dill and cummin. But you have neglected the more important matters of the law—justice, mercy and faithfulness. You should have practiced the latter, without neglecting the former.”
“The Sabbath was made for man, and not man for the Sabbath.”
 Immediately after this incident recorded in 1 Samuel 21 the entire household of Ahimelech the priest was slaughtered by Saul, with the exception of Abiathar, who escaped (1 Samuel 22:6-23). This presents a minor difficulty in understanding, as God — who is longsuffering — apparently chose to overlook or forgive the fact that Ahimelech only helped David because David lied to Ahimelech and claimed that he was going about the king’s business (1 Samuel 21:2-3). At least David later acknowledged his culpability in the matter and confessed it to Abiathar (1 Samuel 22:22).