Valid point overall. But the problem with undercover agents infiltrating terrorists are not really racial slurs. To be accepted among real terrorists, one has to do real terrorism.
(book recommendation: The Little Drummer Girl by John le Carré)
And the news. https://www.google.com/amp/s/amp.theguardian.com/uk/2012/jan...
And about the news links, since we are talking about environmental and animal rights protest groups, I would say the terrorism here comes from the police. Making a baby for better undercover credibility is very low and in no relationship to the threat of the quite harmles activists. But this is a good indicator, of how willing the secret forces are, when it comes to real terrorists. There were years of investigations into the NSU in germany (https://en.wikipedia.org/wiki/National_Socialist_Underground) for example and how close exactly the double agents were to the terrorists and how much involved.
As a version of the "trolley problem" it seems completely unrealistic, but here's a plausible real-life scenario where someone could stop an atrocity by uttering a racial slur: You are an undercover government agent, who has been tasked with infiltrating a far-right extremist group, in order to determine whether they are planning any violent attacks, and to gather evidence to enable their arrest and prosecution. In order to be accepted as a member of the group, you must utter racial slurs. If you refuse to utter them, the group will not accept you as a member, you will fail to infiltrate them, their planned terrorist attack will not be discovered in time, and innocent people will be murdered in an attack on the minorities the slurs target.