Hard and fast divisions between kinds of healthcare practitioners are cemented by the contemporary institutions for training, registering and regulating these practitioners. Before these institutions (especially their modern form, which tends to have arisen through the 19th century) there would have been de facto divisions between people who treated various kinds of health issues, with large overlaps.
In the contemporary world, dentists and optometrists aren't doctors because they don't get the same training as doctors, nor are they registered as doctors. Medical doctors are trained to serve as comprehensive providers of healthcare. This, of course, includes referring patients to various specialists, but it's a part of medical training to have at least a grounding in most specialisations (or at least the most prominent ones).^1 In contrast, dentists and optometrists are trained and expected to deal with a restricted range of health issues, pertaining to the part of the body they concentrate on.^2 Who is certified to work as a doctor is a matter of strict regulation in most jurisdictions, and dentists and optometrists are examples of health professions who don't go through all the hoops, nor are they expected to. They just aren't meant to give the kind of comprehensive medical care a doctor is meant to give. Not that dentists and optometrists work just on the part of the body they concentrate on, but the extent of their interventions on patients is limited, whereas doctors are trained and certified to give comprehensive medical care. Ophthalmologists are doctors who have taken a specialisation in the treatment of the eye, in addition to their training in comprehensive medicine, Oral Medicine is the specialisation doctors may take pertaining to dentistry, though it's not as widely recognised as some others (in many jurisdictions this is a specialisation you can be registered as, in some jurisdictions they are just people who happen to have training in both dentistry and medicine).
Regulation of healthcare provision has a similar history across the West (I can't speak of regulation of medicine in the history of India or China, etc., but they obviously had medical professionals and large bodies of medical knowledge that was passed on amongst professionals). Let's take Britain as an example. There is a petition by a group of surgeons to parliament in 1421 asking the Crown to regulate medical practitioners to stop the harms done by sham doctors; eventually in 1511 Parliament passes such a law investing the Church with the power to regulate, and in 1518 the College of Physicians receives a royal charter to oversee the accreditation of physicians.^3 This isn't the first such body in the UK (the Barber-Surgeons of Dublin dates to 1446) and right from the beginning there is jostling about what kinds of medical practice gets to be the officially accredited type, and on what lines. Lots of different such medical bodies get incorporated over the centuries: dentists would have been included in the 'barber-surgeons' and were a subset of barbers after the surgeons split off in 1745; optometrists get their own body in 1895. The modern system begins in the UK with the Apothocaries Act 1815 which required a particular training for people serving as apothecaries (general practitioners), and the Medical Act of 1858, which sets of a centralised body to oversee the regulation of medical practitioners, including the various specialisations of medicine and healthcare practitioners who aren't doctors (like dentists and eventually optometrists).
Dentistry and optometry have histories of their own. Dentistry is an extremely old profession, with evidence of dental medicine dating back to thousands of years BCE, including dentistry tools circa 7000 BCE in the Indus Valley and various ancient Egyptian texts circa 3000 BCE onwards.^5 Optometry in a recognisable form is much younger, but there are a range of health practitioners dealing with eyes noted throughout history, often under the name of 'oculists', and various medical treatises on the eye.^6
For short statements of what is being involved with being a doctor, see the overviews by the US National Institute of Health here and the UK General Medical Council here.
American Dental Association's statement of duties and responsibilities of dentists and the UK College of Optometry's overview of optometry and eye medicine
J Colson, 'Medical Practice, Urban Politics and Patronage: The London ‘Commonalty’ of Physicians and Surgeons of the 1420s', English Historical Review 2015 preprint, doi:10.1093/ehr/cev261
Ibid
Nice overviews at the American Dental Association and on Wikipedia.
Nice overview again on Wikipedia