"Ye have heard that it hath been said...but I say unto you..."
Jesus was repudiating the Pharisee's misapplication of the Law - not Moses' Law itself.
For example, His comments about the "eye for an eye" line used by Jewish leaders was His explanation of the real intent of that portion of Law in contrast to the way the Pharisees were misapplying it - it wasn't a repudiation of the relevance of Moses' Law.
The Pharisees had been misusing that point of Law as an excuse for revenge and for harshness and inequality in punishment; whereas the real intent of the "eye for an eye" law as given by God through Moses was never meant to be a licence for revenge and was never meant to be taken literally - quite the opposite.
It never meant that if you knock my tooth out, I can literally knock your tooth out. It was only an expression that meant that the restitution demanded by Law had to equal the damage that was incurred - nothing more, nothing less.
It meant that the restitution demanded had to be the same for everyone regardless of the status of the person.
It meant a victim couldn't react in a rage of revenge and determine on his own what would be a fitting compensation for him to exact upon the person who disadvantaged him: the restitution could only be exactly according to the damage.
And it had to be determined at the hands of a magistrate, not a private revenge thing.
In the world of Moses' day, that would have been a new concept of mercy and fairness in law, considering the treatment the Jews had been accustomed to at the hands of their Egyptian slave-drivers!
"Eye for an eye" was actually meant to prevent the kinds of actions which the Pharisees were wrongly using it to justify.
So Jesus illustrated the true intent of the Law by teaching that His diciples would have to do better than the Pharisees - His disciples shouldn't immediately react to a mere slap on the cheek; they should have a certain amount of willingness to suffer a little bit of wrong instead of immediately taking matters into their own hands; they should tolerate others being a little bit demanding of them before drawing the line.
David as King understood the Law in that spirit. And Jesus was bringing His disciples back to what was truly required by God's Law - and in God's Kingdom - in contrast to what the Scribes, Pharisees, ancients and them of old time were wrongly perpetrating.
(This also seems to be the understanding expressed in Wesley's Notes, Jamieson-Fausset-Brown Bible Commentary, People's New Testament, and Geneva Study Bible.)