"Legalism" is a term that gets used in popular Christianity with a range of meanings, but all of them are blurred together. There are at least three kinds of legalism:
- Merit theology - you must obey God's law to go to heaven.
- Adding to God's requirements - in response to God's grace, you must not only obey the Scriptures, but these human traditions as well.
- Judgmentalism - a proud and 'pharisaical' attitude.
These are all connected in a range of ways. Galatians 2:11ff shows that in adding the law of Moses to the gospel (legalism 2) you end up creating a form of merit theology (legalism 1). Likewise, merit theology can feed the pride of the human heart and so lead to the judgmentalism of legalism 3.
But they are not necessarily connected. Someone may believe in merit theology, but be a very gracious, kind person. Or someone may disagree with you about what moral duties are necessarily implications of the gospel, without believing in merit theology.