In the Sermon on the Mount, Jesus showed that under the Law, only perfectly sinless people can enter the kingdom of heaven according to old covenant.
Matthew 5:17-48 “17 “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. 18 For truly I tell you, until heaven and earth disappear, not the smallest letter, not the least stroke of a pen, will by any means disappear from the Law until everything is accomplished. 19 Therefore anyone who sets aside one of the least of these commands and teaches others accordingly will be called least in the kingdom of heaven, but whoever practices and teaches these commands will be called great in the kingdom of heaven. 20 For I tell you that unless your righteousness surpasses that of the Pharisees and the teachers of the law, you will certainly not enter the kingdom of heaven. 21 “You have heard that it was said to the people long ago, ‘You shall not murder, and anyone who murders will be subject to judgment.’ 22 But I tell you that anyone who is angry with a brother or sister will be subject to judgment. Again, anyone who says to a brother or sister, ‘Raca,’ is answerable to the court. And anyone who says, ‘You fool!’ will be in danger of the fire of hell.23 “Therefore, if you are offering your gift at the altar and there remember that your brother or sister has something against you, 24 leave your gift there in front of the altar. First go and be reconciled to them; then come and offer your gift. 25 “Settle matters quickly with your adversary who is taking you to court. Do it while you are still together on the way, or your adversary may hand you over to the judge, and the judge may hand you over to the officer, and you may be thrown into prison. 26 Truly I tell you, you will not get out until you have paid the last penny. 27 “You have heard that it was said, ‘You shall not commit adultery.’ 28 But I tell you that anyone who looks at a woman lustfully has already committed adultery with her in his heart. 29 If your right eye causes you to stumble, gouge it out and throw it away. It is better for you to lose one part of your body than for your whole body to be thrown into hell. 30 And if your right hand causes you to stumble, cut it off and throw it away. It is better for you to lose one part of your body than for your whole body to go into hell. 31 “It has been said, ‘Anyone who divorces his wife must give her a certificate of divorce.’ 32 But I tell you that anyone who divorces his wife, except for sexual immorality, makes her the victim of adultery, and anyone who marries a divorced woman commits adultery.33 “Again, you have heard that it was said to the people long ago, ‘Do not break your oath, but fulfill to the Lord the vows you have made.’ 34 But I tell you, do not swear an oath at all: either by heaven, for it is God’s throne; 35 or by the earth, for it is his footstool; or by Jerusalem, for it is the city of the Great King. 36 And do not swear by your head, for you cannot make even one hair white or black. 37 All you need to say is simply ‘Yes’ or ‘No’; anything beyond this comes from the evil one. 38 “You have heard that it was said, ‘Eye for eye, and tooth for tooth.’ 39 But I tell you, do not resist an evil person. If anyone slaps you on the right cheek, turn to them the other cheek also. 40 And if anyone wants to sue you and take your shirt, hand over your coat as well. 41 If anyone forces you to go one mile, go with them two miles. 42 Give to the one who asks you, and do not turn away from the one who wants to borrow from you. 43 “You have heard that it was said, ‘Love your neighbor and hate your enemy.’ 44 But I tell you, love your enemies and pray for those who persecute you, 45 that you may be children of your Father in heaven. He causes his sun to rise on the evil and the good, and sends rain on the righteous and the unrighteous. 46 If you love those who love you, what reward will you get? Are not even the tax collectors doing that? 47 And if you greet only your own people, what are you doing more than others? Do not even pagans do that? 48 Be perfect, therefore, as your heavenly Father is perfect.”
You see that this standard of sinless perfection is impossible for any human being. The Sermon on the Mount is not a teaching for Christians but it was given to Jews under the Law. Jesus preached the sermon to show that nobody is righteous by the law. Nobody can meet that perfect standard by doing works.
That is why Paul said that nobody is righteous by the law except Jesus Christ. He died for our sins and made us righteous by grace. We simply believe in Jesus to be righteous (sinless) and not by our actions.
Romans 3 “19 Now we know that whatever the law says, it says to those who are under the law, so that every mouth may be silenced and the whole world held accountable to God. 20 Therefore no one will be declared righteous in God’s sight by the works of the law; rather, through the law we become conscious of our sin.21 But now apart from the law the righteousness of God has been made known, to which the Law and the Prophets testify. 22 This righteousness is given through faith in Jesus Christ to all who believe. There is no difference between Jew and Gentile, 23 for all have sinned and fall short of the glory of God, 24 and all are justified freely by his grace through the redemption that came by Christ Jesus. 25 God presented Christ as a sacrifice of atonement, through the shedding of his blood—to be received by faith. “
Jesus alone did not sin and He perfectly obeyed the commandments of the Law. He was the only man who was perfect like the Father. He alone fulfilled the law and then died for our sins on the cross to take away the old covenant and make a new covenant, forgiving all our sins.
Hebrews 10:9-14 “9 Then he said, “Here I am, I have come to do your will.” He sets aside the first to establish the second. 10 And by that will, we have been made holy through the sacrifice of the body of Jesus Christ once for all. 11 Day after day every priest stands and performs his religious duties; again and again he offers the same sacrifices, which can never take away sins. 12 But when this priest had offered for all time one sacrifice for sins, he sat down at the right hand of God, 13 and since that time he waits for his enemies to be made his footstool. 14 For by one sacrifice he has made perfect forever those who are being holy.”