While the Mughal Emperors from Akbar to Aurangzeb were strong rulers, having control over large parts of India, their successors, the later Mughals, who ruled from 1707 (when Aurangzeb died) to 1857 (when the last Mughal Emperor, Bahadur Shah Zafar, was deposed), were mere phantoms or shadows of the departed glory of their ancestors. These later Mughals were Emperors only in name, they were in fact pauperized, they had lost their Empire to the British, the Marathas, and their Governors, who had really became independent rulers (like the Nawabs of Awadh or Nizam of Hyderabad). In their reign the court language gradually ceased to be Persian and instead became Urdu.
Why did the court language which was Persian in the reign of the great Mughals become Urdu in the reign of the later Mughals? This was because the later Mughals were not real Emperors but had become nearer to commoners or paupers with all the difficulties of the common man. Hence they had to take recourse to a language nearer the common man. Why then did their court language not become Khariboli, which was the language of the common man in the cities? That was because these later Mughals, and their Lieutenants, the Nawabs and Wazirs, while having become pauperized retained their dignity, culture and self respect. They still prided themselves in being Shahzade-Timuria i.e. descendants of Timur, the great conqueror, (who was Babar’s grandfather’s great-grandfather) and descendants of the great Mughals. Thus despite having become paupers they were not prepared to be treated as commoners. Hence while they gave up Persian and adopted Khariboli, this was not the Khariboli of the common man but Khariboli of a special type, borrowing from the sophistication, polish and culture of the Persian language. In other words they spoke a Khariboli which was coupled with the graceful features, sophistication and some vocabulary of Persian.
Urdu thus became the language of aristocrats who had become pauperized, but who retained their dignity, pride and respect.