Holding to solid doctrinal beliefs and defending those biblical beliefs is not “legalism”.
Holding to biblical morality and insisting that the church hold to that morality is not “legalism”.
Technically, “legalism” is not even a biblical word.
It’s a word created to describe an attitude one might encounter in a church or in an individual Christian. Specifically, it’s an attitude of one who tries to enforce a set of values or practices that are not specifically biblical. But which might be the accepted norm within a group.
Or an attitude held by someone lacking tolerance for anyone that doesn’t fit a specific standard. Like a Pharisee who tries to get everyone in line with Traditions that are extra-biblical.
Enforcing Traditions that are not specifically spelled out in scripture.
Traditions that are secondary principles. Traditions open to interpretation. And open to the exercise of Christian liberty.