Two male Indonesian soldiers have been given a seven-month jail term for having sex with each other, which is banned by the nation's military as "inappropriate behaviour".

The soldiers, who joined the army last year and were based on the country's main island of Java, were also removed from the army, according to a military court ruling dated 9 November.

While gay sex is barred in the military, it is legal for civilians in the world's biggest Muslim-majority nation, except in conservative province Aceh.

But there is widespread discrimination and some gay Indonesians have been arrested for lewd conduct under anti-pornography laws.

"The defendants' acts of committing deviant sexual behaviour with the same sex was very inappropriate because as soldiers, the defendants should be an example for the people in the defendants' surrounding environment," the 60-page ruling read.

"The defendants' actions were very much against the law or any religious provisions."

The country's Supreme Court posted the decision last week but the case was only brought to light yesterday evening by local news site Detik.

In 2020, Amnesty International said at least 15 members of Indonesia's military or police had been sacked for having same-sex relations in recent years.

"This has been the increasing pattern among the Indonesian armed forces and police in recent years, where members were being fired or taken into court just for who they are, who they love, who they like," Amnesty International Indonesia director Usman Hamid told AFP.

He said "inflammatory statements" by the country's political leaders had helped to further stigmatise minority groups, including the LGBTQ community, adding that the recent case was only "the tip of the iceberg".