GENEVA (Reuters) - Azerbaijan, Egypt and Indonesia have all unjustly arrested dozens of people during anti-gay crackdowns in recent weeks, subjecting many to mistreatment in custody, the United Nations human rights office said on Friday.

“Arresting or detaining people based on their actual or perceived sexual orientation or gender identity is by definition arbitrary and violates international law,” U.N. human rights spokesman Rupert Colville told a news briefing.

In Azerbaijan, more than 80 lesbian, gay, bisexual or transgender (LGBT) people have been arrested since mid-September and the U.N. has received allegations that some were subjected to electric shocks, beatings, forced shaving and other forms of humiliation to force them to incriminate themselves before being released, Colville said.

There was no immediate comment from authorities in Baku.

More than 50 people have been arrested so far in Egypt’s widest anti-gay crackdown, a swift zero-tolerance response to a rare show of public support for LGBT rights in the conservative Muslim country.

Two were arrested for waving rainbow flags at a concert and one for a Facebook page, Colville said.

“In some cases, individuals were reportedly arrested after being entrapped by law enforcement officials on apps and in internet chat rooms. Charges include ‘habitual debauchery’, ‘inciting indecency and debauchery’, and ‘joining a banned group’,” he said.

At least 10 men in Egypt have been sentenced to between one and six years imprisonment, while most others await trial and a few have been released, Colville added.

In Indonesia, more than 50 people were arrested at a sauna in Jakarta last Friday, Colville said. Four men and one woman were charged under the country’s pornography law, a vague statute used to arrest people for consensual same-sex relations, he said.

“In all three countries, authorities have alleged that those arrested were involved in sex work – although in almost all cases the accused have denied such allegations or indicated that they were coerced into confessing involvement,” Colville said.

He called for the release of people detained on the basis of sexual orientation or gender identity and for authorities to drop charges based on vague or discriminatory laws, and to repeal such legislation.