When I was starting out as a barrister in the 1980s, Lord Denning was the most famous judge in the land, and the supposed role model for every lawyer. But not for me.

Not when I was busy defending men already living in fear of HIV and gay-bashing, forced to conduct their sex lives in secret and then victimised for so-called “gross indecency” when caught doing so, in a culture of intimidation created by the likes of Denning.

In 1986, he was one of 13 peers who rose to spout horrific homophobic abuse in support of Lord Halsbury’s bill to stop local councils “promoting homosexuality”, a proposal that led directly to the infamous section 28.

Denning boasted of jailing men for “the abominable offence of buggery”, and warned that “we must not allow this cult of homosexuality, making it equal with heterosexuality, to develop in our land.”

Pride has changed the world for LGBT+ people. Long may it continue | Peter Tatchell Read more

It took LGBT activists 15 years to defeat section 28, but this is not a movement that’s afraid of the long struggle. They know all progress is hard-fought, that discrimination against any individual anywhere is discrimination against all, and that the campaign for true, global equality must therefore be won one issue, case and country at a time. And I hope Lord Denning is spinning in his grave today. Not just because it is Pride weekend, but because, across the world, it is now judges like him in the vanguard of that fight for LGBT equality. Indeed, when it comes to promoting and protecting LGBT rights worldwide, I believe no battle matters more right now than the demand for judicial independence and the rule of law.

Play Video 3:02 The slice of LGBTQ+ history I found in my mate's loft – video

As a barrister, I heard and uttered those terms without knowing what they truly meant, until I experienced countries where the rule of law does not exist, and the judiciary lacks the power or inclination to protect their own citizens equally. It is no surprise that wherever LGBT rights have moved backwards in the past year – places such as Egypt, Turkey, Hungary and Indonesia – it has gone hand-in-hand with the erosion of the rule of law. Because when the LGBT community cannot look to the courts for protection, repressive governments will soon look to target them.

By contrast, from India to Trinidad, it has not been governments or parliaments acting to repeal Denning-era laws against “buggery”, but independent judiciaries ruling in favour of LGBT activists. In Bermuda, it took the supreme court to overturn a government ban on same-sex marriage, rather than Boris Johnson, who shamefully failed to block it.

In Latin America, a landmark opinion from the Inter-American court of human rights in January is now enabling individuals across the region to use the courts in their own countries to assert their right to marriage equality, and challenge discrimination based on their sexuality. And in those countries where governments are trying to roll back LGBT rights, it is the judges standing in their way, not least in Poland, where the supreme court has been attacked by the justice minister for serving “the ideology of homosexual activists”.

It’s time to make Northern Ireland allow same-sex marriage | Conor McGinn Read more

The response of the Polish government is to try to rig the court. And this is the pattern across today’s world: when governments want to attack the rights of the LGBT community, first they come for the judges.

That is one of the many reasons why it is so alarming that Donald Trump has the chance to alter for a generation the balance of the US supreme court, in replacing Justice Anthony Kennedy. While Kennedy’s record on LGBT rights is far from perfect, he did play a crucial role in landmark decisions to strike down laws banning gay sex, and same-sex marriage.

If Trump replaces him with a candidate hand-picked by America’s religious right, those decisions and the rights of LGBT couples in many US states will be under severe threat.

It will take us a huge step backwards from the world we want to live in, where – regardless of where you live or travel – your sexuality should not dictate your rights.

So right now, our best chance of creating that world is to keep fighting for judicial independence in every country, and insist that every government – whether friend or foe – should respect the rule of law.

• Emily Thornberry is Labour MP for Islington South and Finsbury and shadow foreign secretary