If you defeat once, why do you need to defeat 17 times?
Because they were raids designed to loot and cripple the neighbouring Hindu kingdoms, providing revenue for the empire as well as preventing any of their eastern neighbours from developing the capability to threaten their power. It also increased their popularity in the Muslim world as they were stylised as ghazis fighting against the enemies of Islam.
Fact is he entered and plundered India 17 times like a two bit dacoit would.
He was terrible for India, but for the region that is now Afghanistan and Pakistan, he was terrific. Ghazni and Lahore became some of the greatest cities in the region thanks to his conquests. In fact, it wouldn't be a stretch to say that without Mahmud Ghaznavi, Lahore would be just another Punjabi village/town, as he was the one who put it on the map by developing the city greatly and using it as his eastern capital. Without Mahmud Ghaznavi developing the city, I doubt subsequent Muslim warlords would have held it in such high esteem, and as a result Lahore would not be what it is today, and I think that would be a great tragedy.
Also, you cannot deny the man's military genius. He won numerous battles and conquered quite a vast area of land.
And how long did the Mughal rein last?
Effectively, it lasted about two centuries.
Including the non Muslim Akbar who subscribed to Din-e-Ilahi, not Islam.
Din e Ilahi was a social order, not a new religion. And whilst Akbar himself wasn't the most religious, some of the Mughal Empire's most senior figures (e.g Shahbaz Khan Kamboh, a Punjabi general) were, and Akbar himself let the Muslim clergy do their thing (i.e convert people and impose Sharia).