The answer is a simple one, that a number of people have said. If anyone would read the CONTEXT of Matthew 5:43, it is easily & plainly seen. Jesus is NOT quoting OT Scripture; He is simply repeating what those Jewish rabbi's of old TOLD the common Israelites; their interpretational tradition & commentary ABOUT the actual OT Scripture.
Their sayings were not OT Scripture nor was Jesus stating these sayings from those of old, ancient rabbinical interpretations & commentary, were Scripture but that they had replaced the actual Scripture, as traditional sayings.
Jesus corrected these traditional sayings, speaking what God had actually meant. He is the Word of God! He would know what was really meant.
Does the Old Testament teach to hate your enemies? | CARM.org
Is there a Bible contradiction in Matthew 5:43?
You can see the pattern in the context, showing you WHERE these traditional sayings came from & Jesus plain statement BEFORE He started repeating the initial phrase, 'You have heard...'
First, Jesus makes it clear that people were to teach accurately what was WRITTEN in the Law & the Prophets. Not one jot or tittle would be removed nor would anything be 'added' to what GOD SPOKE.
Matt 5:17-19 “Do not think that I have come to abolish the Law or the Prophets; I have not come to abolish them but to fulfill them. FOR TRULY I SAY TO YOU, until heaven & earth pass away, not an iota, not a dot (diacritical mark or part of a letter extension), will pass away from (disappear, be done away with) THE LAW until all is accomplished.
19THEREFORE, whoever breaks (annuls, sets aside, does away with) one of the least of these COMMANDMENTS & teaches others to do the same will be called least in the kingdom of heaven, but whoever does them & teaches them will be called great in the kingdom of heaven.
Deut 4:2 "You shall not add to the word which I am commanding you, nor take away from it, so that you may keep the commandments OF THE LORD YOUR GOD which I command you.
Deut 12:32 See that you do everything I command you; do not add to it or subtract from it.
Deut 1:3 In the 40th year, on the first day of the 11th month, Moses proclaimed to the Israelites EVERYTHING that the LORD had COMMANDED HIM CONCERNING THEM.
Once Jesus establishes the Scriptural baseline of truth, He then gives a series of traditional sayings of the rabbi's or ancients of old, exposing where THIER interpretational commentary ON the Law & the prophets (OT Scripture) was wrong & then what God actually meant from what was WRITTEN.
Matt 5:21 “You have heard that it was said TO THOSE OF OLD (the ancients, ancestors, people long ago), but I say to you...'
Matt 5:27 'You have heard that is was said...but I say to you...'
Matt 5:31 'It was ALSO said...but I say to you...'
Matt 5:33 'AGAIN you have heard that it was said TO THOSE OF OLD...but I say to you...'
Matt 5:38 'You have heard that it was said...but I say to you...'
Matt 5:43 'You have heard that it was said...but I say to you...'
Jesus did very similar teachings in Matt 15:1-20 & Mark 7:1-13.