They invaded a few times, but never really achieved total subjugation for a few reasons.
One factor is the geography of Northern India, which funnels invading forces into incredibly hot and precarious locations. This can be observed most times an attacker reaches India (Such as the Mongols, Alexander, etc). It is noted several times in various documents of natives of the steppes complaining of the heat and weather of India. It was a surprisingly common feature that aids India's longevity.
The Rajputs of the North were also rather fearsome warriors and acted as somewhat of a buffer against invading forces. The north did eventually fall, but the cost was rather high, which saved the rest of India at the time.
It is also possible that the Mongols never pushed the quest for India, as they were pre-occupied in other regions.
It should be noted that Mongol descendants, known as the Mughals like Akbar would conquer India, hence why I said really, as although eventually descendants of the Mongols did, the cultures were vastly different compared to the original Mongols invaders.
hi! you may be interested in this post from the FAQ (link on sidebar)