Let's say that I hate and despise Group X and I want other people to hate and despise Group X. If I was an individual to whom the words "honor" and "integrity" meant nothing, I would then assume an identity as a member of Group X and then make the most hideous and horrible comments imaginable.
The result is a lot of Group X trying to distance themselves from the troll, but a large number of Internet users that already feel ambivalence toward Group X if not outright animosity will find themselves cementing and strengthening their feelings against Group X and all of it based on a lie that cleverly manipulated their minds.
It's a dishonorable and dirty tactic, but very useful. Other helpful terms: Agent provocateur and Black propaganda.
The only way to protect yourself is to be aware that not everybody who says they support something actually supports something.
Trolls are trolls. Don't feed them.
Have a cup of tea instead.