I think Jesus did talk about legalism.
When He said to them that they tithed down to the last exquisite amount but ignored the laws that have to do with mercy and justice for people. He would have been more pleased if they got the weightier matters right but failed in the smaller.
And He was discussing dead legalism when He talked about obeying commands as they were taught by their fathers but only in a dead legalistic way - outwardly - while inwardly they were doing those things in their heart (murder, adultery, etc.)