Their media was clearly inferring that they will fix the problem in a near future and this was the only way for them to get rid of the pressure. They spent their last 15 years to raise police officers, soldiers, doctors and primary school teachers and the government was helping them since they thought that the Gulenists will obey their rules and share their mission by oppressing their non-supporters.
Basically Erdogan took a religious group and made them political and when they had the power, they used it against the government and Erdogan just got away with the accusations with "We were tricked by Gulenists, they're terrorist", nothing more.
Although Gulen still doesn't accept that they did the coup attempt, this was the only way for them to out and even this one was actually hopeless. They have a great hierarchic system so it's hard to keep track of the decision-maker and prove the case so there is no clear evidence, that's why I told "I believe". It's possible that Erdogan knew the coup attempt and yet wait for them (or even convince with third-party organizations) to do it so that we can declare them terrorist without a doubt and do whatever he wants with his followers' support.