Re: the 2016 coup, I’m still not certain that it was a “legitimate” one, ie not sure that Erdogan wasn’t aware of it in its infancy, and decided to allow it to go through.
As others have said, coups are embedded within Turkish democratic history in one sense (though a coup still cannot be a democratic device), so maybe Erdogan has the political acumen to plan ahead including potential coup attempts.
His utilization of the 2016 coup to strengthen his control was astounding in its speed and accuracy. Perhaps this is what enabled western media to think of it as a planned event on the part of the government?