They had no idea of how to deal with an enemy that was content, not to stick around, fight and rule, but to attack, loot and disappear. The Afghan rider would gallop up to the enemy in a cloud of dust, come to a quick stop, turn his horse sideways, release a volley of arrows and as quickly, ride away again. Mahmud attacked India thirty times in as many years, so that Ghazni at the end of his reign rivaled Baghdad in its gardens and in its wealth.
Centuries later, in 1962, another army would use the same technique, on the other Himalayan border. The Chinese, in control of the Tibetan plateau, ran down the North-Eastern slopes and as quickly went away. The Indian army had no way to use their strategy of luring the enemy into the plains and cutting off their supply lines. Not content with doing this once, the Chinese repeated it about a thousand miles north, in the barren mountain ranges of Aksai Chin. This time, they even held on to some territory.
So, what do you do when you have an indefensible border and war-mongering neighbors? If you are India, you chuck off the legacy of Mahatma Gandhi and explode a nuclear device in the Rajastan desert. You develop missiles that have the range to attack the Chinese behind the Himalayan wall. You spend more money on defence than on education. You refuse to sign a Nuclear Non-Proliferation Treaty. None of this is right but the lessons of history can not be easily ignored.
More to the point, no politician who ignores them has a chance of getting re-elected.