Turkish police used tear gas to disperse protesters outside a courthouse in Ankara on Thursday at the start of the trial of two teachers who have been on hunger strike since losing their jobs in a crackdown following last year's failed coup.

Literature professor Nuriye Gulmen and primary school teacher Semih Ozakca have been surviving on liquids and supplements for six months, and doctors have described their condition as dangerously weak.

They were detained in May over alleged links to the militant leftist DHKP-C group, deemed a terrorist organization by Turkey.

Neither they nor their original lawyers were in court at the start of the hearing. The gendarmerie said the defendants might try to escape from the courtroom, despite their weakened state, and arrest warrants were issued this week for 18 of their lawyers.

Police attempted to break up the protests using tear gas, and riot police were present inside and outside the building. At least 20 protesters were detained, being dragged along the ground in the process.

"The first obstacle before a fair trial was the detention of their lawyers, which also served as a veiled intimidation attempt at the judges trying them. Now they are not brought to court, in an open breach of their right to defend," said Baris Yarkadas, a lawmaker from the main opposition Republican People's Party (CHP).

At least a hundred lawyers were present at the courthouse to defend the teachers, along with CHP parliamentarians and the pro-Kurdish opposition Peoples' Democratic Party (HDP).

The teachers have said their hunger strike aimed to draw attention to the plight of roughly 150,000 people suspended or sacked since last July's failed putsch, which President Tayyip Erdogan blames on followers of US-based Muslim cleric Fethullah Gulen. Gulen denies any involvement.

Last month, the European Court of Human Rights rejected a request by the two teachers to order Ankara to release them on health grounds.

Since the failed coup attempt, some 50,000 people including journalists, opposition figures, civil servants and others have been detained in the crackdown.

Rights groups and Turkey's Western allies accuse the government of using the coup as a pretext to muzzle dissent.

Ankara says the purges are necessary due to the gravity of the threats it faces.