Afghanistan was barely even a subject of conversation in this campaign (that itself should be the topic of some investigative reporting), and with mounting U.S. casualties over there in the last couple of years Petraeus would be seen as a huge liability for anyone who was linked to him.
I don’t think it had to do with Afghanistan. I don’t recall exactly when Petraeus ceased to be in charge there, but one of the horrible things that nobody talks about is that US troop deaths under Obama were 2.5 times the entire level of troop deaths in the preceeding 8 Bush years, including when Petraeus was in charge.
And almost all of the Obama deaths were not in military actions, but resulted from attacks by native forces that the commanders had been told they had to include and had to trust. And I think Petraeus approved this.
As I said, Petraeus is a basic military man and does whatever he is told to do by whoever is in charge at that moment, whether he likes it or not. But he must no longer be of any use to Obama.