Classical Sanskrit became fixed with the grammar of Panini (roughly 500 BC), and remains in use as a learned language until the present day.
Over the centuries, the Prakrits underwent language change to a degree that vernaculars and Sanskrit ceased to be intercomprehensible and had to be learned as a separate language, rather than a distinguished or noble register of the popular language. This transition was completed by the Early Middle Ages (Middle Indic), but a significant number of the elite remained fluent in Sanskrit, a situation directly comparable to the role of Latin in Medieval Europe.
Many of the Sanskrit dramas suggest that it coexisted along with prakrits, spoken by those with better education. Prakrits dominated in Magadh, the eastern part of India during the time of Buddha and Mahavira, one of which was likely the ancestor of Pali. Apparently in Gandhara the language remained particularly close to Sanskrit for a long time. Mahmud the Gazanavi used Sanskrit on his coins, and Sanskrit was in use as an official language during early Muslim rule in Kashmir.
Evidence from Rajatarangini
A possible clue to the termination of Sanskrit as a spoken language is provided by Kalhana who describes Samkaravarman (883–902) thus (Stein's trans.):
"Thus this [king], who did not speak the language of the gods but used vulgar speech fit for drunkards, showed that he was descended from a family of spirit-distillers".
kalyapālakule janma tattenaiva pramāṇitaṃ kṣīvocitāpabhraṃśokter daivī vāg asya nābhavat 5-206
This refers to the fact that the power had passed to the brothers of a queen, who was born in a family of spirit-distillers.
Since Kalhana was writing a chronicle (and not a drama), and Samkaravarman lived not too long before his own time, his account suggests that around this time, it was common for Sanskrit to be spoken in noble families, where it was apparently learned by listening.
Use of Sanskrit lingered on in Kashmir even during the Muslim period as is observed by use of Sanskrit on Muslim tombstones and in official documents.
Patronage of Sanskrit Literature by Early Rajput Kings
Early Rajput kings patronized Sanskrit poets. Rashtrakuta King Amoghavarsha is said to have composed a Sanskrit text. Parmara King Bhoja (1010–1053) himself composed and supervised composition of Sanskrit texts. That suggests that Sanskrit was widely spoken and understood in that period by the elite.