Iraq yes, but Afghanistan no. They deliberately allowed terrorists to train and strike from their country, an act of war if you ask me.
after the attack the afghan gov of the time was in agreement that if the US gov bring proof that binladen was connected to the attacks they will judge him or deport him for trial in the US