By Daren Butler

ISTANBUL (Reuters) - Turkish police raided the country's biggest courthouse and two other halls of justice in Istanbul on Monday, detaining dozens of judicial personnel as part of their investigation into last month's attempted military coup.

The raid on the Palace of Justice, which has hosted some of Turkey's most important trials, was a powerful symbol of a post-coup crackdown that has purged Turkey's military, law-and-order, education and justice systems since the failed putsch.

Plain clothes police officers held the arms of the detainees as they escorted them out of the building and into waiting cars. Warrants had been issued for 173 judicial staff, of whom 136 were detained in the raid, the state-run Anadolu agency said.

More than 35,000 people have been detained, of whom 17,000 have been placed under formal arrest, and tens of thousands more suspended since the July 15 putsch, which authorities blame on U.S.-based Muslim cleric Fethullah Gulen and his followers.

President Tayyip Erdogan demands the United States extradite Gulen, and the purge is straining relations with Western allies who Turkish officials say appear more concerned by the crackdown than the failed coup that killed 240 people, mostly civilians.

Police were searching offices at the main courthouse in Istanbul's Caglayan district as well as at two other courthouses on the European side of the city, Anadolu said. The homes of those being detained were also being searched, it said.

In the crackdown since the abortive coup, more than 76,000 civil servants, judges and security force members have been suspended and nearly 5,000 dismissed, Prime Minister Binali Yildirim said on Saturday.

Western officials are concerned the purge will impact stability in the NATO member and a key partner in their war on Islamic State in neighboring Iraq and Syria. Turkish officials counter they are confronting an major internal threat.

With tensions rising with the West, Turkey has sought to normalize relations with Russia, sparking concerns Erdogan and Russian President Vladimir Putin might use their detente to pressure Washington and the European Union.

Also at risk is a deal with the EU on helping stem the flow of migrants into Europe, under which Turkey pledged to stop people leaving its shores and readmit those who crossed into the bloc illegally from Turkey.

Turkey's Foreign Minister Mevlut Cavusoglu told Monday's German newspaper Bild that Turkey could walk away from its promises if the EU fails to grant Turks visa-free travel to the bloc in October.

"It can't be that we implement everything that is good for the EU, but that Turkey gets nothing in return," he told Bild.

EXTRADITE HIM

In keeping with Erdogan's tough line on Gulen, Yildirim told reporters there would be no compromise apart from "this chief terrorist coming to Turkey and being prosecuted," according to Anadolu agency.

Turkish officials say they have handed over documents to U.S. officials concerning Gulen. Washington has been cautious, saying it needs clear evidence before he can be extradited. A U.S. Department of Justice team is due in Turkey this month.

Gulen, who has lived in self-imposed exile in Pennsylvania since 1999, denies any role and condemned the coup bid. Turkish officials describe a network of his followers inside state institutions masterminding the putsch.

Erdogan's critics say he could use the purge to crack down broadly on dissent. A top U.N. rights official last week warned against a "thirst for revenge".

A court in the western city of Izmir has imposed a ban on reporting the statements of suspects and anonymous witnesses in the coup investigation, Turkey's broadcasting authority RTUK said on Sunday.

It said the ban, applying to all media, was taken to ensure that the investigation was sound and conducted in secrecy. Newspapers and broadcasters have given extensive coverage of statements from detained military officers since last month.

In another arrest, a prosecutor in eastern Turkey, who had been suspended under the coup investigation, was detained as he tried to cross the border into Syria on Sunday night, a Turkish government official said.

He said Ekrem Beyaztas, chief prosecutor in Erzurum province, was detained by border guards in Kilis province. There was a warrant for his detention.

"Our initial assessment is that he was trying to reach PYD-controlled parts of northern Syria in an attempt to seek protection," the official said referring to Syria's main Kurdish party, which Turkey considers a terrorist group because of its ties to Kurdish militants in Turkey.

"In recent weeks, runaway coup plotters have been trying to leave Turkey via routes traditionally used by the PKK to smuggle militants and weapons in and out of the country," he said.

Two fugitive staff colonels accused of involvement in the coup were detained in the central Turkish city of Konya along with one person helping to hide them, Anadolu said. They were flown to Istanbul for questioning.

It said one of the officers was accused of commanding soldiers to open fire on protesters on Istanbul's Bosphorus bridge in Istanbul and the other of ordering a raid on the state broadcaster TRT on the night of the coup.

(Editing by David Dolan, Patrick Markey and Peter Graff)