There are a lot of myths being perpetuated as true facts.
First and foremost, the myth of India always having consisted of small kingdoms and being politically weak most of the time.
Let us investigate what we know of Indian history -
We are taught that the 1st pan-Indian empire in Indian history is that of the Mauryans.
However, the Mauryans largely succeeded the empire that had been created by the Nandas 100 years earlier.
When Alexander came to India, politically the North-West was fragmented - the reason being almost all of it had been under the Iranian Achaemenid empire which had fallen to Alexander. However, all the small kingdoms and republics that Alexander fought against were very fierce warriors and the Greeks had a very very tough time. On approaching Gangetic plains, the Greeks learnt that what awaited them was the mighty confederacy of Gangaridai and Prasii who were very powerful. The strength of these confederies deflated the hopes of Alexander's troops and they demanded instant ceasing of further conquests. Read history of Alexander's march in India for more.
The above shows that in Alexander's time, the ancient Indians (Pakistanis & Indians) were quite a military force to reckon with, even when they had small republics & kingdoms.
After the death of Alexander, one of his generals, Seleucus, inherited most of his Iranian empire. This Seleucus, invaded India - which had united under Chandragupta, to conquer those regions that Chandragupta had conquered from Alexander's army after his death. However, Seleucus met with a resounding loss. Rather than winning back those territories, Seleucus lost all his territories between the Indus and the Kabul to Chandragupta. A majority portion of Afghanistan and Baluchistan passed into the hands of Indian political leadership.
Though there were ups and downs, these frontier regions always defined the western boundaries of India for outsiders up until the time of Arabs.
The Persian empire of the Arsacids and Sasanians hardly made any conquests in that frontier region.
When the Arabs finally conquered Sindh in 712 AD, it was after a long decades old effort which started right from 644 AD. However, the Arabs never were able to conquer the Hindu Kingdoms of Kabul and Zabul which straddled Afghanistan and Pakistan. These powerful kingdoms survived upto 870 AD when Zabul finally fell to the Safarids. The Kabul Shahis, however, existed right upto the extinction of their royal house in 1026 AD under Ghaznavi.
So, the frontier of India fought on for more than 3 centuries against the Arabs, who eventually gave up all hope of ever conquering those regions. It was finally left to Mahmud Ghaznavi who conquered them.
-------
The reason why Mahmud Ghaznavi had such a great success in India was due to 2 factors :-
1. The 1st was that he was a very gifted and energetic military leader. There was no comparable leader in India at that time who could match him in these traits.
2. North India, where his campaigns were limited to, had fragmented into smaller kingdoms, after the fall of the mighty Gurjara Pratihara empire. If people are unware of this glorious empire, please search in google, you'll know all there is to know about it. The Pratihars were rulers of North India for more than 2 centuries and were the backbone of Kabul Shahi might in the northwest as well. The Arabs of the 8th & 9th centuries, recorded that the Pratihars were the greatest enemies of Muslims (i.e. the empire of the Caliphate) in India and the small Islamic kingdoms of Mansure & Multan in Sindh, the only remnants of Islamic power in India at that time, greatly feared them. The Arabs, after conquering Sindh, had made inroads into NW India reaching deep into Gujarat and perhaps even Rajasthan & Madhya Pradesh. However, soon enough they were driven back comprehensively and the great state that arose in response to these Arab incursions was the Gurjara Pratihara empire.
Unfortunately for these Pratihars, they had two very powerful neighbouring empires to contend with, the Palas and the Rashtrakutas. The Rashtrakutas were more powerful than the Pratihars. Infact, the Arabs considered them as one of the 4 great empires of the world. These Rashtrakutas almost always defeated the Pratihars whenever they battled each other.
Finally in the 10th century, a great invasion by the Rashtrakutas on the capital of Pratihars, Kannauj, almost totally destroyed their power and the various feudatories of Pratihars carved their own little kingdoms. These various feudatories formed most of what later came to be known as the the Rajput dynasties.
Hence, North India had not recovered from this fall and Ghaznavi entered the right place at the right time. had Ghaznavi met the Pratihars at their peak, he would have been easily driven back to his place and he would not have been the celebrated figure that he is today.
----------------
Similar things can be said about other periods of Indian history but the post will become unreadably long.
To come to the point, Indian civilization was a very vibrant one before the 11th century. It influenced the entire region of South East Asia comprising modern day states of Indonesia, Burma, Malaysia, Cambodia, Thailand, Vietnam etc. All of this region was so thoroughly Indianised that the Arabs considered it a part of Al-Hind.
Similarly, the region of Afghanistan as well as vast majority of regions in Central Asia were heavily influenced by India in their pre-Islamic period. The modern Xinjiang region of China, had several kingdoms in the pre-Islamic period, all of them were heavily Indianised. Indianised also was the region of Balkh or Tokharistan. Sogdiana, a country above Tokharistan, was not Buddhist, but here the Hindu religion (for lack of a better word) deeply influenced these multi-religious people. The influence on China also goes without saying.
Such an enormous amount of cultural influence could not have been wielded by India if it was a people of weak pusillanimous disposition. The evidence clearly shows that in the pre-Islamic period, the Indians must have been a very vibrant, adventurous & brave people.
However all good things come to an end. That is the nature of this world. Indian civilization from the 11th century began to recede and its civilizational footprint began to shrink. It rather began to absorb influences from outside.
There is no shame in accepting that during the period of Islamic invasions, 'Hindu' India was not politically a strong counterweight. However, we should remember that the cause of Hindus was not so hopeless as imagined here :-
1. The powerful Vijayanagar Empire was the richest empire in India at its peak and the Delhi Sultanate or any other contemporary Islamic dynasty in India could not match its richness and affluence. It lasted from 1336 upto 1646. However its political power already greatly declined in 1565.
2. Hemachandra Vikramaditya, also known as Hemu, was on the verge of establishing Hindu rule over Delhi before he died of a freakish arrow in the battle against the teenage Akbar which he was clearly winning.
3. There was Rana Sanga who had defeated Ibrahim Lodhi several times and had ambitions to rule Delhi and hence North India. The greatest battle Babur had in India was not with Lodhi but with Rana Sanga.
4. The Marathas had conquered majority of India at the expense of Mughals before the rise of the British. Infact, the 18th century in India was dominated by the Marathas.