Tobias Basuki, an analyst at the Center for Strategic and International Studies in Jakarta, said the police appeared to be formally taking on a role that had previously been held by hard-line Islamist groups.

“The government is trying to co-opt the religious narrative,” he said.

The Indonesian government, under the leadership of its pluralist president, Joko Widodo, has been engaged in political battles with hard-line Islamist factions that recently succeeded in getting a close presidential ally, Basuki Tjahaja Purnama, Jakarta’s Christian governor, imprisoned on blasphemy charges.

“We urge the government to overturn Mr. Purnama’s sentence on appeal or to extend to him whatever form of clemency may be available under Indonesian law, so that he may be released from prison immediately,” three independent United Nations experts said in a statement on Monday.

Mr. Basuki (no relation to the former governor) said that one way for the government to resist hard-line Islamist groups was to take over the role of enforcing Islamic behavioral norms from vigilantes.

“The police are being seemingly more strict,” he said, “but they will allow less latitude towards vigilante groups.”

Jakarta’s government recently announced that most bars and nightclubs in the city would be closed during Ramadan, a departure from last year, when they were generally allowed to stay open. Over the last few weeks, the police destroyed 16,000 bottles of alcohol being sold by unlicensed vendors in pre-Ramadan raids, according to the local news media.

“There’s a shift in the atmosphere of religiosity in Indonesia,” Mr. Basuki, the analyst, said.

The two young men discovered in bed together in Aceh, who were sentenced last week to caning, are expected to be punished on Tuesday. Activists say they believe the punishment has been scheduled to take place before the start of Ramadan, which begins on Saturday in Indonesia.