Every loss of life was tragic but it was entirely Erdogan and the mosques that told people to attack the soldiers. Otherwise this would have been purely between the military and the police. He was fully aware that he could be sending his people to certain death but he did it knowing that he would be able to use it for publicity no matter which way things played out (bloodbath = martyrs for democracy, surrender = victory of the people).
The coup didn't have to be staged to fail. It was doomed to fail to begin with. The only question is why the military either did not see that or didn't mind failing. Considering how much control Erdogan already had over his country (and even the military) before the coup, it's entirely within reason to consider the possibility that he triggered the coup because there was no way it would harm him.