Obama has two focal options in Afghanistan, “Stay the Course” or “Cut and Run”. Stay the Course means continuing the current counterinsurgency (COIN) strategy of “winning hearts and minds” of Afghan civilians. Cut and Run means getting out as soon as possible and leaving the Afghans to deal with their own mess. In either scenario it is optimal to sack McCrystal.
McCrystal is a strong believer in COIN so if you want to Cut and Run, it s better to replace him with someone else, a true believer in Cut and Run. If Obama wants to Stay the Course, McCrystal is a possible candidate. But there is a reputational cost, looking weak, to Obama of retaining McCrystal. Replacing him carries the risk that the COIN strategy fails. But Petraeus is the author of COIN so this risk is minimized if Petraeus replaces McCrystal. So, even if you want to Stay the Course, it is optimal to sack McCrystal.