Sanskrit was originally an oral language. It began to be written in the Brahmi script and then over time, most of the Brahmi-derived scripts, Gupta, Siddham, Nagari, Devanagari, Purvi Nagari etc. were used to write Sanskrit. But today, Sanskrit seems to be predominantly written in the Devanagari script, for example, Sanskrit textbooks in most Indian schools use it, the official Sanskrit version of Wikipedia uses it etc.
When and how did Devanagari become the dominant script to write Sanskrit?