As in the US, if the original power structure is torn down, a new power structure (based on Islamic fundamentalism) can replace it. Assad stands in the way of this, so the US helps ISIS. In the end, Iran needs to dominant, so the US helps Iran.
Obama plays both sides in an effort to strengthen the ultimate Caliphate.
It's a different take on what Reagan did -- he helped both Iran and Iraq in the 80s as they both fought each other. You play both sides if you have a long-term strategy that benefits from the ebb and flow.
Obama and his inner circle seek that; the rest of the apparatus just follows along.