How and why are PhD programs free in Europe?
I believe what you're talking about is the issue of tuition waivers: that is, are students obligated to pay fees for the tuition, or are those handled by the university.

In many countries in central Europe (including Scandinavia, Benelux, Germany, Switzerland, and Austria) PhD studies are actually paid employee positions, so what tuition charges exist are small, since students normally don't have to take many courses as part of the PhD program (international students may need to register for a few classes to satisfy qualification requirements, but it's not a coursework requirement per se). In other locales, such as as some programs in the US, grants cover tuition charges as well as stipends, preventing students from having to pay those charges. And in many of those countries, the tuition fees amount only to a few hundred euros, not tens of thousands.

It's only where students are expected to do large amounts of coursework and where no arrangements to remit or waive tuition are made that students are responsible for paying large amounts of tuition.