The replacement was a foregone conclusion. The capper on the situation was announcing that he had already had his resignation ready for submission. It remains to be seen whether this was a calculated move on the part of the General or a simple lapse of judgement. Given that Rolling Stone confirmed remarks made by the General by asking for him to corroborate them prior to publishing I am not leaning in the lapse of judgement camp. He may have a significant job already lined up and took this method to get out of an untenable situation, working for the clueless on behalf of the hostile (afghans and congress) to benefit no one before it became impossible to leave without a stigma of defeat.
In short, he just simply had to know what effects his remarks would have and the almost certain result of making them for publication.