ISLAMABAD, Pakistan —Sajjad Ayub knew he was taking a chance. A Pakistani court had just banned public observances of Valentine’s Day in the capital, but he had gone ahead and set up a roadside display of pink rosebud wreaths.

Just before noon, a municipal truck roared up. Several workers got out and swept all his flowers onto the sidewalk. Ayub, 21, waited until they had left, opened a bag hidden under his stand, and pulled out some pink teddy bears.

“I’m a Muslim, and I support the court’s action, but it would be a big business loss for me,” he said with an embarrassed shrug.

At the curb, a line of cars kept pulling up and men in business suits kept jumping out, looking for something to take home to their wives after work. Haroon Khan, 40, a car salesman, picked out a $10 bride-and-groom statuette.

“Life is short,” he said. “If one day a year you give your wife something special to make her smile, what is the harm in that?”

Pakistan, a Muslim democracy of 180 million, is becoming both more Western and more Islamic at the same time. As it moves into the internet era and the global economy, the lines are being drawn more sharply. As more professionals in Islamabad, Lahore and Karachi adopt Western dress and tastes, more members of the vast religious faithful are hewing to the anti-Western rhetoric of radical clerics.

Valentine’s Day is a symbol of that divide, one that is easy to identify with the Western vulgarity and promiscuity that Islamist clerics often rail against.

On Monday, a judge in the federal capital barred all sales, displays, celebrations and media promotion of Valentine’s Day, responding to a petition claiming that the holiday fostered “immorality and indecency” and went against Islamic values and culture, according to news reports.

Like Ayub, many people in Islamabad expressed conflicted feelings or took half-measures to evade but respect the ban. A sidewalk cafe owner covered every table with red petals and hung a mobile of paper hearts. A flower vendor said he agreed with “the mullahs” that Valentine’s Day was forbidden in Islam, but that he just happened to set out all red roses and snapdragons that day.

But the contradictions go much deeper than a debate over permissible public displays of love and affection, a sensitive topic in many Muslim-majority countries and a source of growing conflict in those with both deeply conservative religious traditions and modernizing urban populations.

Pakistan is a country where love is often punished and hatred allowed to flourish. Its media is brimming with televised hate speech against secular liberals, and its family life is often poisoned by honor killings of young women who elope with their sweethearts or try to resist forced marriages.