here is an excerpt of what George Friedman of Stratfor says:
. . . there are deep tensions between Turkey’s secular population, centered in Istanbul and long grounded and comfortable in Ataturk’s philosophy, and Erdogan’s more religious supporters in Anatolia and elsewhere. . . .
Erdogan came to power intending to build a new Turkey. He understood that the Islamic world had changed, that Islam was rising, and that Turkey could not simply remain a secular power. . . There have been persistent reports that Turkey is at least allowing IS to use its financial system, selling its oil in Turkey, and moving its people through Turkey. Erdogan has been, until recently, reluctant to attack them. He shifted his strategy in recent months, resulting in IS attacks on Turkey, apparently in retaliation.
Erdogan is caught between two forces. One is a Jihadist faction that it seems he has tried to manage, to deflect it from hitting Turkey. This effort has put him at odds with the United States and Russia simultaneously. He has also been under pressure from a domestic secular faction appalled by his strategy. Recently the strategy shifted. He reopened relations with Israel and apologized to Russia. He got rid of what many saw as a pro-Islamist prime minister. He appeared to be trying to rebalance his policy. The people who staged the coup likely saw these moves as weakness and sensed an opening.
It should be remembered that Turkey has become the critical country in its greater region. It is the key to any suppression of IS in Syria and even in Iraq. It is the pivot point of Europe’s migrant policy. It is challenging Russia in the Black Sea. The United States needs Turkey, as it has since World War II; and Russia can’t afford a confrontation with it. Neither country likes Erdogan, but it is not clear that either country has options.
In case its not obvious, Russia's main Western year-round port is in the Crimea, and its ships must pass through the Bosphorous Strait. If you control Turkey, you control Russia's Western fleet.