Legalism is trying to achieve right standing before God through keeping the rules of the law (the do's and don'ts of the first five books of the Bible). And as Christians, we are anti legalism. We believe we have right standing before God by his grace through our faith in Jesus, not by keeping the rules of the law. Ephesians 2:8-9 says "God saved you by his grace when you believed. And you can't take credit for this; it is a gift of God. Salvation is not a reward for the good things we have done, so none of us can boast about it." But just because we are anti legalism, doesn't mean we are anti law.
The law of God is a mirror of sorts, showing us our sinful state. Through the mirror of God's law we see that we are sinners and under the curse of the law. But you cannot wash your face with a mirror! Cleansing can only come through the water of God's grace through our faith in Christ. But just because the mirror of God's law cannot cleanse from sin, doesn't mean it's not profitable for other things.
On the contrary, 2 Timothy 3:16-17 says "All Scripture is God-breathed and is useful for teaching, rebuking, correcting and training in righteousness, so that the man of God may be thoroughly equipped for every good work." Remember that when Paul wrote this he was thinking of the Old Testament, because at this time the New Testament had not yet been compiled. Based on this verse we see that the law still has value to instruct and inform (instruct us in God's truths and inform us of God's ways). Just because the law cannot help us obtain right standing before God, doesn't mean it has no value at all.
The law was never given as a means of salvation. It was given to reveal sin and show sinners their need for grace and to instruct and inform God's people on what to believe and how to best live their lives. Look at Deuteronomy 6:24, "The Lord commanded us to obey all these decrees and to fear the Lord our God, so that we might always prosper and be kept alive, as is the case today." The law cannot save from sin, but it was given for our prosperity and preservation. Or look at Deuteronomy 10:12-13, "And now, O Israel, what does the Lord your God ask of you but to fear the Lord your God, to walk in all his ways, to love him, to serve the Lord your God with all your heart and with all your soul, and to observe the Lord's commands and decrees that I am giving you today for your own good?" The law can't save from sin, but it was given for our good!
I don't know about you, but I'm not ready to cast off something that was intended for my prosperity, my preservation and for my good! We are not bound to the letter of the law, but as we read the Old Testament we should invite the Holy Spirit to teach us the spirit of the law. Remember, while the law cannot cleanse us of sin, it still has value to instruct and inform.
Here's just one example of what that would look like. Leviticus 13:4 and 13:31 both teach that if an Old Testament Jew had an infectious skin disease, he was to remain outside the camp for seven days. Remember, in those times they were traveling through the desert, so outside the camp simply meant “away from everybody else”. Now obviously, today, if you have some kind of contagious infection, you aren’t legalistically bound to climb up a mountain and live in isolation for seven days away from everyone else. You don’t have to follow the letter of the law. But following the spirit of the law, you might want to stay home from work if you’re sick so that you don’t get others sick. Or if your kids are sick you might want to not bring them to church, so they don’t get the other kids sick.
So in summary...Legalism is trying to earn salvation by keeping the law. As Christians we are anti legalism, because salvation is by grace through faith. But while we are anti legalism, we are not anti law. Just because the law of God cannot obtain us right standing with God, doesn't mean it has no value whatsoever. The law was given for our prosperity, our preservation and our good. When we read it we aren't bound to the letter of the law, but we'd be wise to invite the Holy Spirit to show us the spirit of the law, because the law still has value in instructing us in God's truths and informing us of God's ways. The law can't save us, but that doesn't mean it's not still useful (2 Timothy 3:16-17) for other things.