They were breaking the "rules" or "safeguards" or guardrails" as interpreted by the teachers of the law who, as you should know, Jesus spoke of when he says " the scribes and pharisees sit on Moses seat, therefore you must do what they say but do not do what they do for they are hypocrites".
Jesus also complained about how burdensome they had made the law and how they had shut the kingdom of heavens doors.
So anyhow Jesus didn't break any of the laws, nor teach others to do so. Given that he himself made the law, he had the authority to interpret it. David ate the showbread as you know, and didn't break the law, because his men were in legitimate need of it.
You know there is a string tied all the way around nyc? It's so the Jews can travel within the whole city on the Sabbath..
Many Christians who read Paul and love their dispensations come to the conclusion they can disregard everything Jesus said before he died and rose again. They then conclude that the law (and the rest of Jesus words) is for the Christians in the millennial reign for when Jesus returns and rules the nations with a rod of iron.
Rules for you but not for me...
Matthew 12:1At that time Jesus went on the sabbath day through the corn; and his disciples were an hungred, and began to pluck the ears of corn and to eat.
2 But when the Pharisees saw it, they said unto him, Behold, thy disciples do that which is not lawful to do upon the sabbath day.
3 But he said unto them, Have ye not read what David did, when he was an hungred, and they that were with him;
4 How he entered into the house of God, and did eat the shewbread, which was not lawful for him to eat, neither for them which were with him, but only for the priests?
5 Or have ye not read in the law, how that on the sabbath days the priests in the temple profane the sabbath, and are blameless?
6 But I say unto you, That in this place is one greater than the temple.
7 But if ye had known what this meaneth, I will have mercy, and not sacrifice, ye would not have condemned the guiltless.
8 For the Son of man is Lord even of the sabbath day.
Let the Lord help us understand what He is saying here.
The only reason those in the temple were guiltless for profaning the sabbath was because they were in the Temple. Yes, Jesus cited the need, but that was not why nor how they were guiltless when He deferred from the temple to One greater than the Temple was here for why His disciples were guiltless, even though there was a hunger need to be met. It is because Jesus Christ was with them, as One greater then the Temple, was why they and saved believers today are guiltless for profaning the sabbath.
2 Corinthians 13:5 Examine yourselves, whether ye be in the faith; prove your own selves. Know ye not your own selves, how that Jesus Christ is in you, except ye be reprobates?
Matthew 28:20 Teaching them to observe all things whatsoever I have commanded you: and, lo, I am with you always, even unto the end of the world. Amen.
1 Corinthians 6:19 What? know ye not that your body is the temple of the Holy Ghost which is in you, which ye have of God, and ye are not your own?
20 For ye are bought with a price: therefore glorify God in your body, and in your spirit, which are God's.
So I am pretty sure you are misunderstanding Jesus's words and Paul's words because the apostle john reduced all the commandments down to 2 which should cover every other commandment for abiding in Him as His disciples.
1 John 3:22 And whatsoever we ask, we receive of him, because we keep his commandments, and do those things that are pleasing in his sight.
23 And this is his commandment, That we should believe on the name of his Son Jesus Christ, and love one another, as he gave us commandment.
24 And he that keepeth his commandments dwelleth in him, and he in him. And hereby we know that he abideth in us, by the Spirit which he hath given us.
It is similar to the other 2 commandments under the Old Covenant.
Matthew 22:36 Master, which is the great commandment in the law?
37 Jesus said unto him, Thou shalt love the Lord thy God with all thy heart, and with all thy soul, and with all thy mind.
38 This is the first and great commandment.
39 And the second is like unto it, Thou shalt love thy neighbour as thyself.
40 On these two commandments hang all the law and the prophets.
Now under the New Covenant, we believe in Jesus Christ as our Saviour that we are saved for simply believing in Him and we believe in Jesus Christ as our Good shepherd to help us to follow Him in all things whereby He gives us His love so we can love our enemies to pray for them for the Father to forgive them for they know not what they do so that IF they should ever be saved or repented, we are ready to greet them with Christ's love when we see them again in Heaven..
So ask Jesus for wisdom and rely on Him to be your Good Shepherd in understanding His words so as to see all His commandments under the New Covenant are something we are to bring to Him for help in doing, but keeping the sabbath is no longer a requirement for salvation as under the Old Covenant because you are saved since having believed in him for eternal life.
Believers are free to honor Him any day, including the sabbath day, but they are to do so not for obtaining salvation as if still under the Old Covenant, but as saved believers just honoring Him that day without judging any body else for not honoring Him that day because they are the Lord's. Once you recognize what He has done for why He is in you & with you always, then there is a rest for the people of God in Christ Jesus for salvation AND for following Him by His grace & by His help.