Dragons as spell casters happened at least partly by accident, I think.
The starting point is that having Dragons as powerful and magical creatures is a desirable trope to accommodate. They are ancient, and wise. Throwing in a few spell like abilities is a good start, but in D&D, if you want...