Ancient India had also suffered invasions from the Greek polytheists under Alexander as well as the Huns who were also considered to be polytheistic, as well as the animist Mongols . So it was not just Christian and Islamic invaders.
Essentially, the various kingdoms and kings in India fought for imperial status, and that is how famous Indian emperors like Chandragupta Maurya, Bindusara, Ashoka the Great, Samudragupta and Vikramaditya came up.
But such reigns by imperial emperors were not present at all times. As long as there was a strong imperial ruler , India was usually safe from foreign invasions.
With increasing time and vast periods of great prosperity and peace, complacency and a lackadaisical approach also came up, which resulted in lack of preparedness against foreign invasions.
Arrogance of the superiority of their traditional political and military systems also prevented the Indians from keeping abreast or informed of the military, sociological and political developments and best practices in other countries, and learning from them and updating their own systems.
For example, when the Mughal invader Babar came to India with cannons and guns, the Indian resistance was led by Rana Sanga armed with mere swords, javelins, bow and arrows and so on. The Indian cavalry came out superior in engagments but eventually the superior artillery of the adversary prevailed.
This was the case also with the western invasions using Indian mercenaries who were trained in modern warfare, and who were able to subjugate the Indian kingdoms.
The two world wars which originated in Europe and lead to heavy fighting between the European nations were factors which substantially weakened them and enabled the countries in Asia, Africa and South America to regain their independence again.