In this excellent summary of Christian theology (which I’ve used to train younger as well as newer Christians), J. I. Packer writes the following about legalism.
“Legalism is a distortion of obedience that can never produce truly good works. Its first fault is that it skews motive and purpose, seeing good deeds as essentially ways to earn more of God’s favor than one has at the moment. Its second fault is arrogance. Belief that one’s labor earns God’s favor begets contempt for those who do not labor in the same way. Its third fault is lovelessness in that its self-advancing purpose squeezes humble kindness and creative compassion out of the heart.”
“So far, then, from enriching our relationship with God, as it seeks to do, legalism in all its forms does the opposite. It puts that relationship in jeopardy and, by stopping us [from] focusing on Christ, it starves our souls while feeding our pride. Legalistic religion in all its forms should be avoided like the plague.”