Just the geography alone of Afghanistan works heavily against any invader.
For example, Alexander the Great lost more of his army in just crossing that country from south to north, than he ever lost in any single battle that he fought. By the time his Greco-Macedonian army had marched through the Hindu Kush mountains then crossed the desert areas to the north of those, it was in a very sorry state. This was further exacerbated when even more of his thirst-stricken men died after gorging themselves on water, once they had reached the Oxus River, on Afghanistan's northern border.
As Winston Churchill once observed "Those that fail to learn from history are doomed to repeat it".