Muslims started attacking India within a few decades of the birth of Islam. For a few hundred years they had no success. Mohammed Bin Qasim was able to defeat Dahir in Sindh but was routed by Bappa Rawal. Qasim attacked Chittore, which was ruled by Mori Rajputs, via Mathura. Bappa, of guhilote dynasty, was a commander in Mori army and so was Dahir's son. Bappa defeated and pursued Bin Qasim through Saurashtra and back to Sindh. After this resounding defeat of the caliphate at the hands of Bappa in 712 A.D., Sindh mulsims paid tribute to Hindu rajputs. (note Muslim historians rarely recorded the defeats of their kings).
Then Mahmud started his raids and was successful in looting Somnath.