The same reason the USA were able to beat the British Empire despite being ridiculously outmatched. The same way Afghanistan defeated Genghis Khan, the British Empire, the USSR and (currently) the USA.I just can't get my head round how the USA didn't beat them so easily
An army or militias fighting on it's own soil will always have the advantage over an invading/occupying force, because they don't need to win they just need to make victory so costly for the invaders/occupiers that it becomes preferable to simply go away.