This question is not just worth understanding in itself but it would be essential to ask at many levels, as science education is becoming the key to the survival of humanity. As a Hungarian who left the country 20 years ago I have been fascinated by this surprising success of the country, partly because I did not personally get a good science education there. Actually, it was very unbalanced, with most of it barely mediocre, while some of it absolutely brilliant. The successful people came from 2-3 high schools (or "gymnasiums", for ages 12-18) in Budapest in the beginning of the 20th century, and whatever success Hungary had in the natural sciences was mostly a result of the work and heritage of that generation. There is a very good description of this in Norman MacRae's book on John von Neumann, worth reading.

A quick summary of the "reasons":

1. Boom: at that time (from 1867 till WWI) Budapest was booming, more attractive to immigrants than New York. Actually, most of the city you can see today was built in those times.

2. Culture: as a result of the boom and the wave of immigrants it became a very liberal and open minded place (though this did not apply to the feudal class at all - their kids typically became soldiers or playboys)

3. Motivation: in a feudal society studying and intellectual eminence was the way to go unless you were born an aristocrat. Parents, students, teachers were willing to put time and money necessary to make their kids excel. This may not sound unusual with all those helicopter parents you see nowadays, but actually this was huge. Imagine growing up in a family where you knew - and your whole family knew - that your only chance of making it is to be the best at math your abilities allow.

4. Education: I don't know where to start, so I can only give examples. Imagine you are a 12 year old child and your teacher borrows you his favourite papers on quantum physics and asks your opinion on them. Then you give a smart comment and your teacher contacts the relevant professor at the university to have a tea with you at your house next Sunday.

5. Language: most of these kids learned Latin and Greek, and in before their teenage years also spoke at least German fluently.

6. The "marble table": Stanislaw Ulam (in his autobiography, another amazing read) and also MacRae tells about the most important ingredient, the marble table at the café (the easy-to-erase whiteboard of the time). In Central Europe mathematicians met at cafeterias, discussed all day (often meaning 12 hour days at a cafe!), challenged each other, and did rarely work in isolation, not worrying too much about "who thought of it first". They happily took young kids in, 15 year olds sipping juice and 50 year old Banach drinking something much stronger (may not have been Banach, but you'll read the book!). It was such a well-known "way of doing math" that the IAS in Princeton was officially established to re-create this culture and pull the typical American professors out of their ivory towers.

It is an elitist system, I know, and does not solve mass education challenges. But this small elite circle had an impact on almost everyone in the country's education system. Even if you weren't a Wigner, Teller or Neumann, you spent 6 years in this environment and possibly became a great teacher, similar to the one who taught half of these people, the great László Rácz [1] and taught in this fashion.

Also, a similar great science education happened in Japan at some point (50's, I think ), but I only read this as a side note in the book on Neumann. Anyway, it is possible to do this again and with two small kids I'm very interested to know how.

[1] https://en.wikipedia.org/wiki/L%C3%A1szl%C3%B3_R%C3%A1tz