So tell me, why was it that Europe was nearly conquered by the Arabs and a lot of it occupied for several centuries. They got to the Loire in France around 730 CE. So that was half of France.
The last Arabs were finally ejected from Spain in 1492, only 500 years ago. They'd been there for 800 years.
The whole of the North African coast, thousands of miles, and South to the Equator, is still held by Arabs after the conquests of around 700 CE, so roughly 1300 years ago.
This is a miscomparison of tenses. The peninsular Arab armies of 700-1300 were unstoppable. But the parent commenter is asking about the armies of the modern era.
Actually a more interesting question is why /regular/ armies organized by the State in such countries are generally perceived as hopeless whereas /irregular/ militias such as we see in Afghanistan have proven so effective. It's clearly not a people thing since they are drawn from the same well.