The Pharisees often get painted as sticklers for the law; legalists. Some think that they missed the spirit of the law because of their slavish adherence to the letter. I disagree. It was not attending to the letter that caused the Pharisees that Jesus rebuked and criticized to miss the spirit. Their problem wasn’t keeping the law, which is decidedly good, but rather substituting a standard of their own for the law. Too many workarounds; too much attending to the minutia while neglecting the weightier matters.
Someone said on Twitter the other day that legalism is lowering the bar and acting as if you’ve raised it (or something to that effect). That seems like an apt description of the Pharisees that Jesus rebuked (and I’m careful to single them out since there were plenty of Pharisees in the first century who were okay; think Joseph of Arimathea). So keeping the law was never an issue; hypocrisy was. That’s why we have a text like Matthew 7 where Jesus rebukes them for judging according to a standard that they do not live according to themselves.