Seven years ago this month, I played my small part in legal action that ended a discriminatory “anti-gay” law in Uganda, offering hope to millions in Africa’s LGBTQI+ community.

Passed unanimously in an inquorate parliament by both government and opposition members — save my own and one other dissenting vote — the legislation made homosexuality a capital offense. It had already been signed into law by the time I and my fellow rights campaigners sought its cancellation by the courts.

Few rated our chances of success in the face of overwhelming political headwinds; fewer still when, in the midst of the hearings, Uganda’s leading pop artist Bobi Wine fanned the flames of public opinion with a chart-topping song — “If you a man” — calling for homosexuals to be burned to death.

But win, we did. The law was unanimously overturned by the five judges on the Constitutional Court. The government declined to appeal. The decision demonstrated loud and clear that, armed with the facts, the Ugandan courts are more than prepared to rule in favor of those opposing official policy. The public reaction was different: both I and my fellow parliamentarian who opposed the legislation paid a heavy political price when we lost our seats at the subsequent election.

Yet for many international commentators, the independence of the judicial system was the more surprising. Most lazily assumed, this being Africa, the court would roll over and succumb to political and public pressure.

This indolent opinion of African judges incapable of independent, non-political action has been disproven time and again: in Kenya the 2017 general election was overturned by the courts and the contest re-run; and last year in Malawi a fraudulent national ballot was canceled and ordered to be repeated.

There are many more examples from Uganda. Several involve Bobi Wine, now former pop-star-turned-opposition leader, who ran for president earlier this year.

Wine knows better than most the power of an independent judiciary. Time and again it has saved both him and his nascent political career. Over the last four years, he petitioned the High Court, winning when the government attempted to have his political party de-registered, and winning again to be released when arrested for campaigning during a COVID curfew. Then, immediately after the count when the police illegally surrounded his home, he won a High Court ruling ordering them to leave.

But Wine did not win the election. No doubt feeling pressure from his disappointed voters and western supporters, he inevitably lodged a court petition calling for the vote to be overturned. Yet soon after, he pulled the challenge.

The fault lay not with lack of evidence, he claimed, but the lack of independence of the judiciary. Every time questions of his liberty were put before them, they ruled in his favor: but now the judges were ripe for trashing. Only weeks after his previous victory in the very same courtroom, Wine stated “the courts are not independent, it is clear these people are working for the President."

After the release of his anti-gay song, Wine was awarded a richly deserved visa ban from Britain. Today he says his views on homosexuality have changed. We must hope to believe him. Some western parliamentarians are convinced — one going as far as to call him "charismatic, brave and popular."

Yet his view on justice and the rule of law are unchanged. When the courts rule in his favor, they have his support; when he has no case, he uses his public position to pressurize and sully them – and then head to the streets.

There is, of course, electoral fraud in Uganda. There is electoral fraud every place that holds elections. In Malawi the court ruled it sufficient to overturn the result. But the question Wine and his international supporters are yet to answer is – just as in the United States last year - were there sufficient irregularities to put the outcome in doubt?

Wine alleges — now in the “court of public opinion” — that he possesses 137 affidavits supporting 26 grounds that, apparently, prove that the 2.4 million vote margin between him and the winner is fake. If he were correct, it represents electoral trickery so ingenious it, surely, would be easier to imagine those capable of such a deception talented enough to win an election in the normal way.

The truth remains Wine and supporters have little by way of evidence: a case based on minor infringements would fail before any dispassionate court. So, they pull the case and instead they trash independent judges and demean a robust legal system. This talk supposedly justifies their distribution of leaflets with images of burning flames and demands for the inauguration of the election winner to be halted by "people power."

This is dangerous. The challenges we faced seven years ago to overturn an anti-gay law needed both a cogent case and an independent judiciary to which we could appeal in a country that is – for all its faults – underpinned by the rule of law.

A country where “people power” reigns, judges are maligned and electoral grievance is dragged from the courtroom onto the ghetto is not the kind of country where anti-gay laws are withdrawn after legal appeal; it is the kind where, soon enough, they are imposed – regardless of the courts or the rights of the people.

Fox Odoi-Oywelowo is a human rights lawyer and Ugandan Member of Parliament-Elect.