The History of 'Doctor'
Just who qualifies as a doctor anyway?
It's a familiar trope in television and movies: someone has an emergency medical need in a public setting far from medical care. A loud call is heard: "We need doctor! Is there a doctor in the house?"
You know who doesn't answer that call? Your friend with the PhD in astronomy/literature/basketry.
The reason your friend doesn't answer that call is because they're smart enough to know that the word doctor in modern English is most often used to refer to a person who knows the healing arts and who's trained and licensed to use those healing arts. Your friend has a PhD, after all, which means they're bright enough to have gone through (at the very least) years of coursework, exams, a dissertation, and a defense of that dissertation.
But what your friend also knows is that while doctor most often refers to a medical doctor, academic doctors can rightfully claim it too. And they have lexical and etymological evidence to back their claim.
The English language history of doctor starts in the early 14th century, when the word was first applied to a select few who likely knew neither bloodwork nor basketwork. They were equipped for dealing with matters of the soul: they were eminent theologians who had a special seal of approval from the Roman Catholic Church as people able to talk about and explain the doctrines of the Church. They were teachers of a kind, and the word's origin makes this connection. The word doctor comes from the Latin word for "teacher," itself from docēre, meaning "to teach."
The 14th century was the birth of the Renaissance, and lots of teaching and learning was afoot. By the century's end, the word doctor was being applied not just to a select few theologians, but also to qualified and/or accomplished academics and medical practitioners.
In the centuries between then and now, doctor has had many other applications, including referencing a soldering tool, a tropical sea breeze, and a loaded die. It's almost exclusively used of people now, and both qualified academics and medical practitioners may rightfully claim it.