The place where Kabul's main mosque stands today was the site of an ancient Hindu temple and the story of its capture is kept alive in Islamic Afghan legend which describes the Islamic hero Sabuktagin who fought with a sword in every hand to defeat the Hindus and destroy their temple to put up a Mosque in its place. (This is not being mentioned here to reclaim the place as a temple. But to record a long forgotten fact that today's Islamic battlefield of the Taliban was once inhabited by Hindus.)
The victory of Sabuktagin pushed the frontiers of the Hindu kingdom of the Shahis from Kabul to behind the Hindu Kush mountains (Hindu Kush is literally "killer of Hindus" - a name given by Mahmud Ghazni to describe the number of Hindus who died on their way into Afghanistan to a life of captivity) . After this setback, the Shahis shifted their capital from Kubha (Kabul) to Udbhandapura (modern Und in NWFP). Sabuktagin's son Mahmud Ghazni, kept up the attacks on the Shahis and captured Und. Subsequently, the Shahis moved their capital to Lahore and later to Kangra in Himachal.
The defeat of the Shahis opened up the Gangetic plains to the Muslims and Mahmud Ghazni repeatedly attacked the main Hindu kingdoms ruled by the Gurjara-Pratiharas and sacked Hindu temples. The main ruler in those days was Rajyapala Pratihara who resisted Mahmud Ghazni's raids, partly successfully. In his last attack on Somnath, Mahmud Ghazni successfully sacked the temple at Prabhasa Patan in Gujarat, but on his way back he was roundly defeated by the Gujar rulers of North Gujarat. Mahmud never came back to India after that. (Refer to the Glory that was Gujar Desha by K.M. Munshi) But these first Muslim raids into India proper had given an ominous indication of what was to come a couple of centuries later in the year 1194 C.E.
But for now, the Muslim rule of the Ghaznivids was established in Kabul, Paktoonistan and in the land of the five rivers - Punjab. Thus after Sindh in 715; Kabul, Paktoonistan, and Punjab became the next Indian provinces which went under Muslim domination in the period 980 C.E. to 1020 C.E.