Although from an outside perspective a military coup seems completely undemocratic the Turkish military has historically had the role of maintaining the principles Atatürk founded the Turkish Republic on. You can think of them as a built-in correction mechanism in case the government veers too far off course -- they remove the government, reset everything to start and then hand over control back to the people once th…
Its not just Erdogan. People of Turkey seem to be supporters of this path. Although its very sad.
I don't know what changed in Turkey but it now seems that his support has grown not only outside the country but also within and he seems to be hellbent on exploiting religion to gain political support. I don't know whether he actually holds fundamentalist views himself but he certainly knows how to use them to his advantage.
[0]: https://en.wikipedia.org/wiki/Headscarf_controversy_in_Turke...