Under rightwing and leftwing governments alike, India has prided itself on its status as the world's largest democracy. Civic freedoms, an independent judiciary, and basic political rights for citizens are part of that promise. But in India and far too many other democracies, rights that are arguably even more basic – to be who you are, to live freely in your body, even to call yourself a citizen if society despises you – are a different matter.

Early on October 20, Bangalore police arrested five hijras – a traditional cultural identity for working-class transgender people who, born as men, identify as women. Such arrests are sadly routine. Throughout India, many hijras cannot get identity papers: the state will not let them change their legal sex and denies them IDs if their appearance does not match their birth gender. As a result, they often cannot work, go to school, find jobs, vote, or even move around freely. Social prejudice against "men" or "women" who are not "masculine" or "feminine" enough makes them ready victims of violence.

Denied viable opportunities for work, hijras are forced to resort to begging or demanding goodwill funds during marriage or birth celebrations. That way of life has been part of several regional Indian cultures, where blessings of a hijra were considered a good omen. But as these traditions erode, many hijras have had to survive as street beggars or sex workers. In both cases, police slap them with fines, jail them, sometimes physically or sexually abuse them.

But on October 20, the five hijras, who were apparently begging but not soliciting sex, were charged with "extortion" – a crime which, unlike begging, allowed the police to hold them without bail.

In India's vibrant civil society, a growing number of NGOs support the sexually – as well as politically and economically – disenfranchised. A crisis intervention team from the Bangalore-based organisation Sangama, which works to protect and advance the rights of sexual minorities, arrived at the police station to help. The group is trained to assist hijras in fending off barrages of minor charges. But this time, the police jailed the five members of the crisis intervention team as well, beating and sexually abusing some of them.

The situation escalated after about 150 activists from a wide range of social movements – lesbian and gay, hijras, feminists, trade union leaders, Dalit activists – gathered outside the station for a peaceful protest. The police invited six of them into the station, ostensibly for a dialogue, then arrested them. Two women among them were sexually assaulted, one of them kicked and beaten by a police inspector when she demanded he not touch her breasts. However, none of the six were charged.

In conversations with Human Rights Watch, one of the activists said that this points towards the distinct class prejudice at work in such instances of abuse. "The police obviously thought that we were the 'leaders' of the organisation, so they didn't charge us whereas they thought the others were just workers and they could treat them worse."

Meanwhile, police attacked the protesters outside the station, charging them with batons. They rounded up 31 of them, beat them, threw them into a police van, and drove them away. They were held without food or water for almost 18 hours. At the height of the police violence, 60 police personnel stood guard over the 31 activists.

Eventually, the hijras and the human rights defenders were freed, though many still face charges that include "unlawful assembly" and "rioting." The press reported – and police confirmed to the activists they arrested – that this was the start of a drive by local authorities to contain what they called the "eunuch menace", citing public complaints against hijras as justification. A police official told one jailed activist who demanded an end to the violence and the human rights abuses: "Yes, this is human rights violations, so what? Stop us if you can."

The poor and disempowered are no "menace". But prejudice is. Indian democracy is still riven, and endangered, by deep divisions. These shocking arrests show how people whose bodies and sexualities put them beyond the pale of social norms are effectively without rights in the eyes of the police.

The violence also shows, though, how anyone who defends sexual rights can also become a target of abuse, arrest, and, in some cases, sexual violence.

The High Court in Delhi is in the last stages of deciding a challenge to Section 377 of the Indian Penal Code. This law, a British colonial invention, criminalises "carnal intercourse against the order of nature". Human rights activists want it reinterpreted to end the criminalisation of adult, consensual homosexual conduct.

Casting off that regressive colonial burden is crucial. But the events in Bangalore – the splashy city that is the showcase of India's capitalist modernisation – reveal other burdens, some modified from the colonial era, that still weigh on the country.

One is the Immoral Trafficking Prevention Act of 1956, passed following independent India's ratification of a 1950 international convention, which can be traced back to the colonial-era Contagious Diseases Act. The 1956 law gives police wide leeway to arrest and abuse sex workers, and it has been used against HIV outreach workers and others who behave in ways authorities simply do not like. Contemporary anti-begging laws are a throwback on colonial "vagrancy" laws, which gave colonial officials power to control the "natives". Now they serve to keep an underclass in subjection and fear.

More crucially, though, the divisions of poverty still weigh on the country. And poverty and the effects of prejudice reinforce and intensify each other. People who already face discrimination and hatred, including many sexual minorities, remain shut out from the promise of prosperity from the establishment of call centres and high-tech firms in Bangalore. What prosperity has resulted has not trickled down to the lower classes among the despised and disenfranchised.

The Bangalore violence is a ringing challenge to Indian authorities, a reminder that democratic institutions are no cause for self-congratulation if their doors are closed to many who need them. "Stop us if you can," the police told the human rights defenders they arrested and abused. India's democracy must address all the intersecting forms of economic, political, and prejudicial exclusion that lead to such a slap in its face–otherwise the violence will not stop.

Dipika Nath has a doctoral degree in feminist studies and works as a researcher in the LGBT rights programme at Human Rights Watch.