President Hassan Rouhani, who came to office in 2013 partly on the votes of young, middle-class women, knows that in the summer, hundreds or even thousands will be arrested by the morality police for “bad hijab”, a slack interpretation of the official dress code requiring women to cover their hair and figure even as temperatures push 40 degrees.

In his remark last year that “you can’t send people to heaven by the whip”, the president expressed a belief that citizens should not be forced into “good” behaviour, and in two recent speeches he skirted the issue of hijab, provoking a critical response from Ayatollah Ali Khamenei, the supreme leader, and from senior members of the clergy.

In late April, the president told an assembly of Iranian police officers the duty of the police was solely to enforce the law. “The police’s job is not to enforce Islam, and furthermore, none among them can claim that their actions are sanctioned by God or the prophet [Mohammad].”

Although Rouhani stopped short of mentioning the harassment of women with bad hijab, he made a break from the period of his predecessor Mahmoud Ahmadinejad when then police commander Morteza Ahmadi Moghaddam stressed that the “philosophy at the heart of the Islamic republic was the presence of religion in society” and so “the police must act to ensure that this goal is met”.

Rouhani’s offered a different vision: “Many religious issues are merely matters of individual faith,” he said. “Police come into the picture only when an actual law…clearly and explicitly applies. For example, during mid-day prayers, could the police enter a bank and tell the employees that they must halt all business to pray?”

Rouhani’s comments made a splash the next day on the front pages of many reformist papers, including Shargh, Etemad, Mardom Salari and Arman. But it wasn’t long before he received a response.

Khamenei appeared just a day later before an assembly of police commanders, making it clear that enforcing Islam was the police’s first priority: “All work can be done in the name of God, but in your work it is most easy to see how God’s will can be done. That is because your duty is to serve the society of the Islamic republic.”

A member of the editorial board at Etemad told Tehran Bureau the leader had several motives in replying to Rouhani. “Firstly, he wanted to demonstrate his dominance over domestic affairs. Secondly, he wanted to show that in his view, Islam supersedes the law. And finally, he wanted to offer a kind of rebuke to Rouhani for getting out of line.”

One analyst saw a connection with April’s interim nuclear agreement with world powers at Lausanne. “This disappointed many of Khamenei’s most ardent supporters, and they imagined that his leniency toward the west might translate to leniency in the domestic arena, which would allow Rouhani to take up reform with little resistance,” she said. “Khamenei’s immediate response is part of his efforts to assuage his anxious supporters and remind them that flexibility toward the western powers doesn’t necessarily mean moderation in domestic policies.”

But Khamenei’s intervention also opened the door for others to enter the fray. Ayatollah Makarem Shirazi, a senior Shia cleric, told another group of police commanders that Rouhani’s remarks not only weakened “the morale of the police” but gave “the green light for corrupt elements to introduce all manner of filth into society without any repercussion or response from the police”.

Ayatollah Nouri Hamedani pointed out that Iran’s constitution came “straight from Islamic criteria” and that the idea the police should not enforce Islam precluded the concept of “enjoining the good and forbidding the evil” in society, a notion found in the Qur’an. Ayatollah Mohammad Yazdi, chairman of the Assembly of Experts, the clerical body that chooses the supreme leader, threatened the president with serious consequences: “The executive branch cannot deny Islam; it must uphold it. If it denies Islam, Islam will deny it in turn.”

Mohsen Kadivar, visiting professor in Islamic philosophy at Duke university, North Carolina, and an influential reformist thinker of the 1990s and 2000s, said that Rouhani had expressed basic principles that were fundamental to all modern states.

“Managing the nation on the basis of law is the cornerstone of the contemporary nation-state system, so to negate that in any way is to invite chaos,” he said. “The announcement by the supreme leader and a few other marjas [leading clerics] that the police and everyone else should uphold Islam is a denial of the fundamentals of law, an agent of disorder, and a rejection of the rule of law.”

Kadivar said the arguments of those criticising Rouhani were incompatible with the “multiple interpretation” of sacred texts in all religions. “For example, different jurists and muftis will put forth various, sometimes conflicting fatwas. On which fatwa should the police or any other agents of the state rely when enforcing Islam?”

Neither did the problems end there. “If judges and police forego the law and act on fatwas, we will find ourselves back to the days of 100 years ago, when Iranians went to the streets to demand a constitution. According to the constitution of the Islamic republic, the law is decided upon solely by the parliament. The Guardian Council [a constitutional watchdog], whose members are [partly] selected by the supreme leader, is tasked with making sure laws passed in parliament conform to the decrees of Islam. Therefore, laws in the Islamic republic are passed under the supervision of appointees of the supreme leader, so there is no conflict with the supposed need to uphold Islam.”

Despite all criticism he faced, Rouhani returned to the issue of bad hijab and law enforcement in a speech on 4 May before a group of teachers, in which he said that “Colt- and handcuff-toting agents of the regime” should not be expected to “act as religious scholars.”

Three generations of Iranian women, three different styles of hijab. Photograph: Kamyar Adl/flickr

In the Tandis luxury shopping centre, north Tehran, a young woman named Maryam told Tehran Bureau that Rouhani’s campaign was important to her. “Sir, madam, what right do you have to say whether my hijab is proper or improper?? Can you show me the hijab-o-meter they issued you when you took this job? Where in the Islamic texts does it say that in 21st century Tajrish [quarter of north Tehran] there’s a girl with bad hijab whose offences to Islam must be stopped?

“Rouhani must do the right thing and stand by his word. He has to stick up for our rights and not allow these brutes with guns and badges to insult us and have their way with us. Most of them haven’t even finished tenth grade? Where do they come off insulting and arresting someone with a master’s degree in front of everyone?”

At this month’s recent Tehran International Book Fair, vans of morality police flanked the entrance to the book fair as had been promised by police spokesman Montazer Almahdi at a press conference. “Essentially the morality patrols are for protecting the dignity of men and women and act as a kind of hijab for the society of the Islamic Republic,” he insisted.

Mahtab, a woman at the fair in conservative attire, said the situation was ridiculous.

“I’m a religious person myself - I prefer to wear the hijab - but who said you have to force everyone else to wear it? Some people don’t want to wear it. What does it have to do with you? Why don’t they respect the law? Who said it’s their duty to force everyone into heaven?”

The conflict over whether or not people should be dragged into heaven is set to continue.

“Rouhani is testing the limits of his power to forbid the police from visiting violence upon our people,” a member of the banned reformist party Participation Front told Tehran Bureau. “Restricting morality patrols is the beginning of Rouhani’s project for gradually extracting Islamic ideology from the practice of law. Just what he is willing to sacrifice for this project remains to be seen.”