MOSCOW — More than 50 gay and transgender people in Azerbaijan’s capital, Baku, were detained and abused in a series of raids over the past week, lawyers and rights activists said.

The Azerbaijani government said the raids were prompted by multiple complaints from local residents, who had urged the police to crack down on the illegal sex trade in central Baku, a city of more than two million.

However, lawyers and activists said that most of those detained were not engaged in prostitution and that the accusations were used as a pretext for persecution.

Samed Rahimli, a lawyer assisting the victims, said the police had “targeted homosexuals in general, not prostitutes as they have claimed.”