Persian was popular before the Mughals, as the presence of multiple well-known Persian poets can show. The Mughals themselves wrote and spoke Turkish. For example, the Mughal ruler Babur (d. 1530) wrote memoirs in Turkish. Pre-Mughal Northern India spoke in what was called Hindavi, Dehlavi, and Rekhta--mixed dialects which would we would mostly call Hindi now.
Though many languages were in use under the Mughals, Persian did experience a dramatic rise in usage. There is debate as to what caused this rise. Mughal rulers communicated with rulers in the Greater Iran/Greater Persia region; Akbar (d. 1605) was especially interested in Persian, and sent away for Persian poets and intellectuals to come to India. Many came, probably owing at least in part to Akbar's more tolerant policies on religion compared to the (fairly recent for them) establishment of the Safavids as Twelvers in 1501. Akbar established an official job for a court poet, and everyone who got the job was Iranian except for one, who wrote in Persian, too. Akbar also made Persian the language not just of the highest nobility, but of all levels of administration. Before that, administrative issues were usually carried out in Hindavi.
If you were a noble in the Mughal empire, regardless of religion, you would know Persian and Hindavi (probably a few variations on your local variety), and you might have learned Arabic. Labels get more complicated in the eighteenth century, when you might have instead been able to say that you knew Persian, Hindi, Urdu, Punjabi, Kashmiri, Prakrit, etc.
Source: Muzaffar Alam's article, "The Pursuit of Persian: Language in Mughal Politics" (1998) and his book The Languages of Political Islam: India, 1200-1800 (2004)