I gave you three examples of legalism from scripture. In Matthew 7:22, we see legalism in which these many people try to use their works as a resume to earn God's favor to receive eternal life. Jesus rejects them and with these words, "I
never knew you; depart from me you who practice lawlessness," (which means they were
never saved) and shows they were trusting in their works for salvation and not in Jesus Christ alone. Their outward religious acts were not a substitute for a personal relationship with the Lord (John 17:3) or doing the will of the Father. (John 6:40) In context, Jesus warns about
false prophets (Matthew 7:15) and contrasts good trees which bear good fruit with
bad trees that bear bad fruit. (Matthew 7:17)
In Luke 18:9-12, Jesus exposes legalism and self-righteousness through the parable of the Pharisee and the tax collector. The Pharisee boasts in his strict religious performance, fasting twice weekly and tithing, while looking down on others, which shows how legalism breeds spiritual pride instead of a right relationship with the Lord. Luke 18:13 - And the tax collector, standing afar off, would not so much as raise his eyes to heaven, but beat his breast, saying,
‘God, be merciful to me a sinner!’ 14 I tell you;
this man went down to his house justified rather than the other; for everyone who exalts himself will be humbled, and he who humbles himself will be exalted.”
In Romans 10:1-4, Paul addresses legalism by explaining that religious zeal and rule following cannot earn a person with a right standing with God. He points out that Israel had a
zeal for God but not according to knowledge. By trying to set up their own standard of righteousness through the law, they
failed to submit to the righteousness of God and accept that Christ is the end of the law for righteousness to everyone who believes.
Those verses show that seeking salvation by works (self-righteousness/legalism) is not obedience. Unlike genuine obedience from a right relationship with God is not legalism.
Claiming to serve Jesus apart from doing the will of the Father which instead results in practicing lawlessness stems from legalism.
Self-righteousness is not obedience. Keeping the commandments becomes legalism when obedience shifts from a loving response to Jesus into a performance-based effort to earn God's favor, secure righteousness and measure one's spiritual superiority over others. Keeping the commandments is designed as an expression of love from a relationship with the Lord and not as a legalistic prescription to earn salvation.
In regard to Matthew 19:17, Jesus showed the rich young ruler how short he falls of keeping even the first commandment (
Exodus 20:3) which is the first of the two great commandments. (
Deuteronomy 6:5;
Matthew 22:37) The rich young ruler confidently and (self-righteously) declared that he has kept the commandments from his youth up and qualified for heaven under those terms yet Jesus knew the man's wealth had become his idolatrous god, which kept him from believing in Jesus unto salvation (
John 3:18) so he has not kept the commandments from his youth up. The rich young ruler missed the point that Jesus was making, failed to place his faith in Jesus for salvation, and continued instead to trust in his riches (
Matthew 19:21-23). He went away sad because he could not part from his great wealth, not even in exchange for eternal life.