A little background on Turkey and coups
After World War I led to the collapse of the decrepit Ottoman Empire, the modern Turkish state was established by Kemal Atatürk, perhaps history's best example of a charismatic leader who changed the course of a whole country's development. Atatürk, an atheist, was determined to make the new Turkish state as modern and Western as possible in every respect, including both democracy and secularism. By and large the republic he founded has remained true to his vision; by the 1950s it had evolved a genuinely democratic system, and the state has remained secular.
Yet there remains a tension between the two goals. In a nation whose population is mostly Muslim and many people still believe that Islam should influence government, there is always the risk of secularism being eroded by Islamic-leaning elected governments. The Turkish military, one of the country's most solidly secular institutions (this is a common pattern in the Middle East -- an effective military has to understand technology and other realities not very compatible with a superstitious world-view), has long viewed itself as the guardian of Atatürk's legacy. Several times from the 1960s to the 1990s, the military either threatened the government with a coup or actually carried one out, at least in part because elected leaders were introducing religion into government (in most cases there was also significant economic turmoil or street violence which the state seemed unable to cope with). In each case, however, the military left power and restored democracy as soon as the crisis had passed. Bizarre as it may seem, the Turkish military could be viewed as having a role similar to that of the US Supreme Court -- exercising a final veto in cases where elected leaders transgress against the essential principles of the state.
The current Erdoğan government is aggressively Islamist and has also openly attacked essential elements of freedom, such as freedom of the press. In light of precedent, it is almost surprising that the military did not act earlier. Part of the explanation is the fact that Turkey has for years supposedly been under consideration to be admitted to the European Union as a member. While it's unlikely that Turkey will ever actually be accepted by the EU, the EU has made it clear to Turkey that, to qualify, the military must stay out of politics. Not only is this ironic in view of the flagrant lack of democracy in the EU's own institutions, but it has weakened the chief bulwark of Turkey's secularism, allowing Erdoğan to push an Islamist agenda and erode free institutions, threatening the survival of Turkish democracy itself.
The collapse of this week's coup reflects the fact that only a portion of the military was involved, with other units opposing it. Evidently the generals failed to reach consensus. But from every viewpoint, the implications of this event are discouraging. It shows that almost eighty years after Atatürk's death, Turkey still seems to need the military as the chief safeguard of its secular republic -- and that now even that safeguard is failing.