what does the bible say?
David's eating of the showbread was a violation of the Mosaic law God had given to His people. God's love and mercy underlie the law, so Jesus cites David's actions to reveal the Pharisees' "hardness of heart" (Mark 3:5). The Mosaic law specified that each Sabbath, twelve loaves of fresh bread were to be placed on the gold table in the tabernacle (later, the temple) (Leviticus 24:5-6). The loaves that were removed from the previous week were to be Aaron's and his sons' (and thereafter, other priests and their sons) (Leviticus 24:5-9). But 1 Samuel recounts an incident in which David and his men were fleeing from Saul and stopped by the tabernacle in Nob because they were hungry. The only bread available was that which belonged to the priest and his sons, but David asked for it anyway because he and his men needed food (1 Samuel 21:1-6).
In three of the four Gospels, Jesus refers to that account after the Pharisees chastise He and His disciples for doing "work" on the Sabbath—though they weren't, according to the law (Matthew 12:3-8; Mark 2:25-28, 3:1-5; Luke 6:3-4). Jesus wasn't sanctioning lawbreaking; He was using David's story to show that God's mercy underlies His law (Hosea 6:6). The Pharisees were using the law to lord it over others rather than understanding that God's heart is the foundation of His commands (Matthew 23). Jesus referencing the account of David eating the showbread is one among many examples showing that God is not pleased by empty ritual but by those whose actions reveal love for Him (Isaiah 1:13-17; Amos 5:21-24; Matthew 15:8-9).