It wasn't retaliation, because the Taliban didn't mastermind the 9-11 attacks. The 9-11 attacks were most likely funded and orchestrated by Saudi Arabians.
The reason the US attacked Afghanistan was because the Afghan government refused to hand over some people the US suspected of being involved. The Afghan government wanted to see some evidence first. That's a reasonable demand. We always want to see evidence in OUR countries before extraditing people to other nations. The US certainly always wants to see some evidence.
But of course, there's one rule for us and one rule for poor underdeveloped countries.
So instead of providing evidence, we invaded.
So of course the war wasn't justified, as diplomatic channels were not pursued in any meaningful way beforehand. War must be a last option to be justified at all.