Indonesia is probably the most populous country Westerners don't really care about.

The massive Southeast Asian nation doesn't really figure in international politics. It has a history of non-alignment. It's an emerging market that never seems to emerge. And when it does pop up in the news, outside of its quite common natural disasters, people often don't understand it: a moderate Muslim-majority nation of 250 million people that sends fewer fighters to the Islamic State group than Britain or France?

This is why many have been confused by the supposedly sanguine nation's harsh treatment of foreign detainees. By going forward with both the executions of the Bali Nine drug traffickers last year and pushing forward with the repeated prosecution of Canadian Neil Bantleman, the country's government has confused and confounded international observers and foreign governments alike. But what many fail to see is that Indonesia's defiant positions play out largely for a domestic audience, one just getting a handle on democracy after decades under Suharto.

Story continues below advertisement

Indonesian politicians and judges will clearly not stand for drug trafficking, for example, as seen in the case of the Bali Nine. And certainly, they won't stand for sexual crimes committed against children, as is sensationally – and very dubiously – alleged against former international school vice-principal Mr. Bantleman and teaching assistant Ferdinant Tjiong. Despite the fact many Indonesians – online and in protests – objected to these aggressive prosecutions, both cases fit within the broader moral panic being whipped up about supposed vices in Indonesia, whether drugs or homosexuality.

And this, despite the various outrages: With the Bali Nine, one of the men sentenced with death was a Brazilian who was both bipolar and schizophrenic – he didn't even know he was going to be executed until he was led to the firing squad.

With Mr. Bantleman's case – which has been condemned for irregularities by the U.S., British and Australian embassies, as well as by Canada's Foreign Minister – it is hard to know where to begin. The original claims expanded to effectively allege an organized pedophile ring among top administrators of the prestigious school for the kids of diplomats and executives, conducted – and occasionally filmed – inside their offices. All of their offices, of course, have walls made entirely of glass and are located in the school's front hall. There is no physical evidence from examinations of the boys.

The parents of the alleged victims also launched a $125-million (U.S.) lawsuit against the school, shortly after expanding their accusations from janitors (who were employed by a contractor) to the school's actual staff members. The mother of one of the boys involved, who sent various e-mails and WhatsApp messages to other parents alleging the administrators sexually abused her son, also failed to show up for – and thus lost by default – a defamation suit launched against her in Singapore, a country that, unlike Indonesia, has a credible judiciary. Let's not forget that Mr. Bantleman is also alleged to have conjured up a magic stone from thin air with which he anesthetized his supposed child victims. More seriously, one of the six accused janitors died in police custody – allegedly by suicide – while others said they were forced to sign confessions.

Story continues below advertisement

Mr. Bantleman and Mr. Tjiong were eventually acquitted, but the country's Supreme Court overturned that acquittal and sentenced them to 11 years in prison. They are now pursuing a review of that decision.

Indonesian government officials remain divided on the case: Some see something "fishy" that could be a legal attack on a school that occupies a huge chunk of land in Jakarta, while others think he's guilty. But one thing is absolutely obvious: The still relatively new President, Joko Widodo, who narrowly won an election against a Suharto-era strongman, has very little wiggle room in terms of appearing "tough" – on drug traffickers, of course, but most certainly on alleged child molesters. He also can't be seen, in a democracy, to interfere in the judicial system.

But there is also something else going on.

Tom Pepinsky, an associate professor at Cornell University and president of the American Institute for Indonesian Studies, says the two cases came at a time when the public is "in the midst of a dramatic upswing in anti-LGBT discourse." He has noted, for example, that the broadcast regulator has ruled that a man on TV is not allowed to "talk like a woman." The Defence Minister called homosexuality a proxy war against Indonesia, while a mayor said eating instant noodles could turn one's baby gay. One politician tweeted that Islamic jurisprudence condones the killing of homosexuals.

Story continues below advertisement

"The idea that foreigners are potentially threatening, and that vice issues like drugs and sex are vectors for pollution or contamination of Indonesian society, is an old saw in Indonesian politics," Prof. Pepinsky says. "It is a fundamentally nationalist impulse, a holdover from the revolutionary and early independence periods. It comes from the same place that spawned the Indonesian military's perception that it needs to prepare for a guerrilla warfare defence against some kind of looming external threat."

Mr. Bantleman's detention, in this context, begins to seem less absurd, more part of an allergic reaction within Indonesia to any form of potentially negative outside influence. Understanding that, of course, does not make his case any less outrageous. In fact, it makes it even worse.