No one can explain the mission in Afghanistan.
The actions (or lack thereof) in Libya, Egypt, Iran and Syria are not compelling on either side.
There is a pretty simple “explanation” for Afghanistan. It is an example of the necessary, if unpleasant, projection of American power in order to kill our enemies. Now the efficacy of that project can be questioned no doubt but not the intent.
My own view is that we need bases in Iraq and Afghanistan far into the future.