Erdogan was quoted by the state-run Anatolian news agency as saying on Saturday that "expecting such protests and reactions in future and commending such actions is not the right thing to do".
He was referring to comments by General Hilmi Ozkok, Turkey's Chief of General Staff, who urged people to continue protests in defence of secularism.
Erdogan rejected the general's comments, saying: "People holding responsible positions should know well what to recommend and how,"
"The protest incident turned into an accomplishment for terror," he said.
Erdogan's Islamist-leaning Justice and Development Party (AKP) has often confronted Turkey's secular establishment, chiefly represented by the powerful military, over a headscarf ban, restrictions on religious education and alcohol use.
Ozkok's call was seen as a warning to the government from the army, which helped topple an Islamist-leaning government in 1997, and follows comments in leading papers that the government should learn lessons from the mass pro-secular protests.
Ismet Berkan, editor in chief of the respected liberal daily, Radikal, wrote on Saturday that "Turkey is heading towards a very dangerous political polarisation. The government had better consider the situation calmly".
Secularists accuse the AKP of having a hidden Islamist agenda and cite recent attempts to restrict alcohol consumption and ease restrictions on religious education. The AKP denies it.
"People holding responsible positions should know well what to recommend and how"
Turkish Prime Minister
Headscarves have become a symbol of a broader struggle over the role of religion in the European Union applicant country.
Protests on Thursday against the killing a day earlier of the judge turned into a rowdy demonstration against the government.
Police detained nine people in connection with the shooting of the judge. Anatolian said another man, a former army officer who the assailant had telephoned prior to the attack, was also detained on Saturday.