Law and medicine are advanced degrees.
They're not really. They're professional degrees, just like engineering. It's not typical anymore in the US to go straight into medicine from high school, but lots of schools either require only a year or two of "pre-med" or have "accelerated programs" where you do a bachelor's degree and an MD at the same time. Other professional schools are often similar, requiring some post-secondary education before you can be admitted.
Medical specialization is arguably analogous to graduate studies, although it's more like an apprenticeship, focused on practical learning before professional licensure, and engineering and law often require the same, although law seems not to in the US.
MDs being styled as advanced degrees goes back to when some Scottish medical school decided that their medical graduates were "senior scholars" and should be given the title "doctor" in the 17th century. Which is silly, because "doctor" is Latin for "teacher." Some law schools have jumped on board and give out JDs, which must get confusing because there are also actual doctorates in law.