How were people able to graduate with a PhD at a such young age in the past?
There are several issues:


Your examples are somewhat biased, since you've selected researchers who were not only brilliant but also prodigies.  By contrast, Riemann finished his Ph.D. dissertation at the somewhat older age of 25, and Weierstrass didn't start his research career until he was 39 or so.  Brilliant researchers are more likely to get an early start than average researchers are, but the correlation is far from perfect.  Focusing on prodigies gives a misleading picture.
There are plenty of prodigies today (Terry Tao, Noam Elkies, Akshay Venkatesh, Erik Demaine, etc.).  If they occupy a smaller fraction of academia, it's probably because academia has grown enormously even relative to the population.  The faculty in the top departments today are stronger on average than a hundred years ago, but there are many more departments nowadays, so the average professor is overall probably not as talented.
The amount that's known is steadily increasing, so getting to the 19th century research frontier takes quite a bit less time than getting to the 21st century research frontier.  This is not as relevant in very new fields, but finishing a Ph.D. in algebraic geometry in two years is a more impressive feat today than it was a hundred years ago.  This increase in knowledge doesn't translate perfectly into an increase in time to degree: people also compensate by specializing more and then broadening later in their career.  However, the obstacles to a quick Ph.D. are certainly increasing over time.