Asking for whether a German university is better than another makes roughly as much sense whether craftspeople in one city are better than in another: Sure, some businesses are better than others, one city will have the very best craftsperson, and maybe one of the cities has a vibrant plumbing community leading to a significantly better quality of plumbing in that city. However, at the end of the day, this will have little effect on the average quality of a services or help you select a particular service: If you need your violin repaired, it doesn’t help you that the world’s best hair stylist lives next door.
Similarly, the idea that a university is generally better than another is – prima facie – absurd:
If a university has one of the world’s leading historians or is best at teaching biology to its students, this tells you very little of the quality of teaching or research at its math department.
You may have a strong correlation of quality within an institute, a modest one within a department, but this becomes negligible once you go to the faculty or university level.
The main thing that connects different faculties within a university are its central services (administration, cantina, etc.), but these barely affect teaching and research quality.
Thus I think the question rather is: Why do other countries have such high difference in university quality? I think the main reasons are:
Reputation feedback loop: A good reputation attracts better students and personnel, which in turn leads to better teaching and research, which leads to a better reputation. More on this in this answer of mine.
Financial feedback loop: More money allows you to hire better researchers and teachers, have a higher teacher-to-student ratio, and perform more expensive research, which in turn allows you to acquire more money from student fees, sponsors, and grants.
Historical bias: For example, in the US most (if not all) top universities are rather old or were funded with insane amounts of money (see the previous point). Young universities usually have bad chances of acquiring a reputation etc.
As German universities are state-funded, the financial loop is mostly absent. Also, this limits the reputation loop: Why should the state fund more room or personnel at one university when there is unused space and personnel elsewhere? As for the historical aspect, Germany had many universities before it became feasible for most students and personnel to select a university solely based on quality aspects as opposed to geographical ones. Those were of comparable quality for the same reason outlined in the initial example with craftspeople.
As far as I understand, there is a high degree of self governance for the German state governments to choose the policy in regards to their universities, so I'd imagine a higher variance in quality by state.
Kind of. On the one hand things such as finances are largely homogenised, so they don’t factor into this. On the other hand, for other aspects so much freedom is left to the individual faculties, and departments that the effects smear out at the university level. For example most physics departments in Germany adhere to rather similar standards of teaching, but this is completely different from how any law department operates.