We de-Nazified the Nazis, and nation-built in Germany. We de-militarized the Japanese government, and nation-built in Japan. We were unwilling to de-Islamize in Afghanistan and Iraq, and the results are plain.
Nation building in the country of a former adversary in war is a poor idea IF you are not willing and able to take appropriate drastic action to suppress and eliminate the ideology that you were battling. We weren’t, aren’t, and likely will not be for the foreseeable future.
Beyond that, see tagline.
I don’t think Germany and Japan are comparable to Iraq and Afghanistan, but I understand your point.
Germany are Germans. Japan are Japanese[grammar]. However, Iraq and Afghanistan, are tribes. Islamists will cross borders to support such actions. War goes on forever, you would have to deIslamize the entire ME for 'victory'.
We had a similar problem in Korea and Vietnam. If those countries didn't have outside support or if we were willing to attack the countries that supported them, there would have been a chance of 'victory'. But, Vietnam had plenty of avenues of aid pouring in.