I think the real distinction is that terrorists are non-state actors who use violence (bad). States are legally allowed to use violence (necessary).
But the common parlance of terrorist usually means "US designated terrorist" which really means "group we refuse to bargain with".
The Taliban were a terrorist group, now they are a government. The Iraqi army was a legitimate army, then many became ISIS, a terrorist group.