In 2003, the justification for the US invasion of Iraq centered around a lot of bogus allegations. Among them were claims that Saddam Hussein’s Ba’athist government, a relatively secular militaristic government, was secretly in bed with al-Qaeda. The claims were false, at the time.
12+ years later, those allegations have become something of a self-fulfilling prophesy, as the war and the excesses of the ‘de-Ba’athification’ campaign that followed ended up driving Sunni Arabs in the old Iraqi military out, and the persecution that followed eventually drove them into bed with ISIS.
While ISIS’ political leadership remains mostly religious leaders who were with them from back in the days when they were al-Qaeda in Iraq (AQI), the establishment of the caliphate as a proper nation-state has produced a separate ISIS military leadership. A new army looking for commanders and a bunch of seasoned commanders looking for a purpose after being shut out of the new Iraqi military, it was inevitable they’d find each other.
The big question though is whether this could’ve been avoided. The US decided early on during the Iraqi occupation to destroy the military and then create a new one out of whole cloth. This left them desperate to train up a new military while the Shi’ite political leadership did its best to freeze out anyone even tangentially related to the old guard.
In many ways this is why the Iraqi military has been so ineffective, as it is full of relative newcomers and militia cast-offs, hastily trained and armed and sent to fight forces with much more experience. Now, to make matters worse, those enemies are commanded by the actual career military men who the US was so eager to ditch.