Last week Jeremy Corbyn was branded a “terrorist sympathiser” by a heckler in Glasgow, who demanded to know where his “Islamic jihad scarf” could be found.

The moment, gleefully covered by the rightwing press, lost some of its lustre when it emerged that the heckler, a Church of Scotland minister called Richard Cameron, allegedly had a back catalogue of Islamophobic and homophobic tweets. But the reverend’s terrorist sympathiser insult did not come out of nowhere. David Cameron, then serving as prime minister, denounced Corbyn and his colleagues in precisely the same terms when he opposed airstrikes in Syria in December 2015. And Boris Johnson accused Jeremy Corbyn of seeking to “legitimate the actions of terrorists” in his speech after the 2017 Manchester bombing.

Johnson seemed confident that public opinion would share his view of Corbyn’s speech as “absolutely monstrous”. But polls suggested that the majority of people agreed with the Labour leader that terrorist attacks on British soil were connected, at least in part, to the country’s foreign policy. The “terrorist sympathiser” label appears to be as subjective as the word “terrorist” itself.

Much of the criticism directed at Corbyn focuses on his relationship with Sinn Féin in the 1980s and 90s. During the 2017 general election campaign, Boris Johnson tweeted a photo of Corbyn with Martin McGuinness in 1995, deriding his claim to have never met the IRA: “You cannot trust this man!” By the time that photo was taken, the Sinn Féin leader, Gerry Adams, had already shaken hands with the then US president, Bill Clinton; two years later, McGuinness would be a guest in Downing Street. It has been widely reported that Adams and McGuinness were still members of the IRA’s army council at the time. But Clinton, Tony Blair and the Unionist leader David Trimble all held talks with them in their capacity as Sinn Féin politicians – a distinction vital for the entire peace process.

While successive prime ministers insisted publicly that they would never “talk with terrorists”, there was in fact discreet contact between British government officials and the IRA throughout the conflict. William Whitelaw, the secretary of state for Northern Ireland at the time, even negotiated directly with the IRA leadership during the truce of 1972. Pragmatic considerations trumped any sense of moral outrage.

Corbyn’s critics insist that his record of engagement with Irish republicans is very different, because he supported their political goals. It’s quite true that leading voices of the British Labour left argued for Irish unity in the 1980s, much to the displeasure of unionists in Britain and Northern Ireland alike. Corbyn himself wasn’t a prominent figure at the time, and became an MP only in 1983; Ken Livingstone, then head of the Greater London Council, was much better known, and his comments on the Northern Irish conflict attracted a great deal of controversy. If support for a united Ireland made Corbyn and Livingstone into fellow travellers of the IRA, by the same logic, those who defended the union with Britain shared a political objective with the loyalist paramilitaries responsible for hundreds of deaths during the Troubles. The argument of guilt by association can easily backfire on those who deploy it.

The Labour leader has also faced sharp criticism for his meeting with representatives of Hamas in 2009. But even Mike Gapes, the former Labour MP who is one of Corbyn’s fiercest critics, had called for talks with the “moderate” elements of Hamas in 2007, and Tony Blair later described the boycott of Hamas after it won the 2006 Palestinian elections as a mistake. Blair himself met in private the Hamas leaders Khaled Meshaal and Ismail Haniyeh only four years ago.

And while Corbyn expressed “regret” for using the term “friends” in reference to delegates from Hamas – after it elicited an indignant response from critics – there was no such outrage when Conservative and Labour politicians referred to the Saudi royal family as valued “friends”, allies and partners of the UK in the course of a parliamentary debate on continued arms sales for the Yemen war, which those MPs supported. It is certainly difficult to imagine a consistent set of principles for a prospective British prime minister that would put Hamas beyond the pale yet allow for a close relationship with the Saudi Arabian monarchy, given the UK’s support for its war in Yemen, which has killed tens of thousands of civilians.

Of course, violence against civilians – from the Isis-inspired massacres in France to the deliberate targeting of civilians in Yemen – is a crime in all circumstances. But the way we talk about terrorism, and the application of the “terrorist” label by governments, has always been arbitrary and self-serving. In the 1980s, Margaret Thatcher and Ronald Reagan denounced the African National Congress in South Africa as terrorists, while supporting insurgent groups elsewhere whose record of violence against civilians was incomparably worse, from Angola to Afghanistan, Cambodia to Nicaragua. The Clinton administration initially branded the Kosovo Liberation Army (KLA) as a terrorist organisation, before enlisting it as an ally against Slobodan Milosevic. In recent years, the US and the UK have kept the Kurdistan Workers Party (PKK) on their list of proscribed terrorist groups, but accepted Syrian groups closely linked with the PKK as partners in the war against Isis. “Terrorism”, in this sense, is simply the use of violence by non-state groups without the blessing of the US State Department.

If Corbyn had been willing to internalise this value system and its peculiar set of taboos, he would have attracted much less controversy in his time as Labour leader. But the foreign policy consensus works much better when it doesn’t have to be explicitly articulated by those who support it. Insults such as “terrorist sympathiser” are meant to discourage awkward questions about the double standards that govern Britain’s relationship with the outside world.

• Daniel Finn is a journalist and historian from Ireland, and author of One Man’s Terrorist: A Political History of the IRA