The decision to block access to the websites came in the afternoon from a court in southeastern Diyarbakir, which ordered a ban to links that displayed the caricature, according to Turkey’s state-run Anadolu news agency.

“The prophet of a religion that an individual and the society believe in is indisputably an indispensable value for that religion that needs to be respected,” the court said in its decision, adding that freedom of speech is curtailed by personal rights and doesn’t allow an individual to say “whatever” the person wants to another person.

Meanwhile, dozens of riot police sealed off the roads to Cumhuriyet’s Istanbul headquarters, following an official raid shortly after midnight on its printing house as editors planned to prominently publish the image of Muhammad in solidarity with the 12 people killed by extremists at the satirical magazine’s Paris offices last week.

Cumhuriyet said that Turkish authorities allowed Wednesday’s edition to reach store shelves after an inspection showed that the cartoon of Muhammad wasn’t printed on the cover, but inside the paper atop two opinion columns.

ENLARGE
Utku Cakirözer, the editor in chief of Cumhuriyet, in his office on Wednesday.AGENCE FRANCE-PRESSE/GETTY IMAGES

“When publishing this selection [of latest Charlie Hebdo cartoons], we paid attention to the freedom of belief and the religious sensitivities of societies,” said Utku Cakirözer, Cumhuriyet’s editor in chief on his Twitteraccount. “After multiple consultations, we decided not to publish on the cover.”

Turkey’s public debate on free speech versus religious values contrasted with its Muslim neighbors in the Middle East, where leaders from Egypt to the Palestinian territories and Iran unanimously slammed Charlie Hebdo’s depiction of Muhammad as a provocative act. But the deep divides that played out over social media in Turkey throughout Wednesday also illustrated the polarization of its society, where hardening differences between President Recep Tayyip Erdogan ’s pious supporters and his secularist opposition are becoming more difficult to reconcile.

“I’m increasingly worried about the language that is being used, the threats, the blackmailing, and the fact that police were sent to Cumhuriyet. If the Charlie Hebdo cover had been printed, they would have halted the newspaper’s distribution—symbolically, this is very bad,” said Soli Ozel, an international relations lecturer at Kadir Has University in Istanbul and columnist at the mainstream Haber Turk newspaper. “Turkey has shown that at the end of the day it still follows the path set by Erdogan with regards to free speech, especially when it comes to religious matters.”

Treading a more nuanced line than its Muslim neighbors, Turkish officials said while they condemn the Paris attacks, the government also stands vehemently against attacks on Islam.

“Those who publish imagery referring to our esteemed prophet with complete disregard for Muslims’ holy beliefs are engaging in an open provocation,” Deputy Prime Minister Yalcin Akdogan said in message on Twitter.

When publishing this selection [of latest Charlie Hebdo cartoons], we paid attention to the freedom of belief and the religious sensitivities of societies.

—Utku Cakirözer, editor in chief of Cumhuriyet.

But Turkey’s opposition lawmakers defied the government’s stance, visiting Cumhuriyet’s Ankara bureau to express solidarity. While some said that the paper’s decision to print Charlie Hebdo content showed its support for free speech, others warned against provocations and called for common sense.

Umut Oran, a lawmaker from the secular Republican People’s Party, or CHP, submitted a parliamentary inquiry to Prime Minister Ahmet Davutoglu, demanding to know who had ordered the raid on the distribution center.

Mr. Davutoglu traveled to Paris over the weekend to march with world leaders in a display of unity following last week’s attacks in Paris, which left a total of 17 people dead. Turkey has been embroiled in the drama after it emerged that Hayat Boumeddiene —the common-law wife of one of the attackers, Amedy Coulibaly —traveled through the country en route to Syria as the attacks were taking place. Turkey’s Islamist-rooted government and Mr. Erdogan have condemned the attacks but also warned against a rising tide of Islamophobia in Europe that is feeding extremism.

On social media, the Cumhuriyet appeared to highlight divisions between secular and religious members of society. The top trending tweet in Turkey on Wednesday was #ÜlkemdeCharlieHebdoDağıtılamaz—meaning Charlie Hebdo Cannot Be Distributed In My Country—indicating discomfort among swaths of the public over the publication. Liberal Turks, including high-profile journalists, academics and activists criticized the raid against Cumhuriyet, saying that it fit a pattern of increased censorship of free speech.

Following the Diyarbakir court’s ban on websites displaying the Muhammad cartoon, Turkey’s Internet users quickly resorted to various means to bypass the blockades. Having experienced periods of government-promoted bans on social sites such as YouTube and Twitter, and learning to navigate through thousands of banned websites, they once again used methods such as VPNs and changing IP addresses to overcome the blockades.

The court decision also failed to stop online platforms in Turkey from carrying the cartoons, with independent online news site T24 publishing a Turkish translation of Charlie Hebdo’s latest issue in its entirety.

Cumhuriyet—an avowedly antigovernment newspaper seen as reflecting the dogmatically secular legacy of modern Turkey’s founder Mustafa Kemal Atatürk—was the only mainstream daily to print the images in solidarity, although they were also published by some online publications. Some pro-government newspapers criticized the outlets on their websites.

“Big provocation from Cumhuriyet writers,” the pro-government daily Yeni Safak said on its Twitter account. Islamist newspaper Yeni Akit headlined its front page “The Infamy Continues,” saying that the West “did not learn its lesson.”

Amid mounting tensions, police detained at least three people as they protested in front of Cumhuriyet’s Istanbul headquarters. Authorities and the newspaper haven’t specified the duration of heightened security, which was still intact as evening settled.

Turkey’s main weekly satirical magazines—three of which published a joint cover this week declaring “Je Suis Charlie Hebdo” on a black background—have received a surge of threats on social media from anonymous Turkish Islamists and accounts suspected to be those of pro-government provocateurs, as well as heavy criticism from Islamic-leaning pro-government media.

“Since we blackened our website last week after the attacks, we started receiving a massive amount of threats, including death threats and threats to burn down or destroy our premises. Some read ‘12 dead will not be enough for you, you should be killed in bigger numbers’,” said Zafer Aknar, an editor at LeMan cartoon magazine, which has more than 80 contributors to its weekly issues.

Despite the threat, LeMan hadn’t increased security or taken any other measures against attackers.

“We are used to threats. Government supporters shower us with threats when satirizing Mr. Erdogan, or Mr. Davutoglu, but the threats we received recently exceeded all that,” Mr. Aknar said.

—Asa Fitch contributed to this article.

Write to Ayla Albayrak at ayla.albayrak@wsj.com and Emre Peker atemre.peker@wsj.com