if the war were to last for 20 years, the majority of refugees should
be able to obtain citizenship and would not have to return to Ukraine.
Is there an estimate of how long it would take for most refugees to
gain a permanent status in their host country?
This assumption is more wrong than right.
Usually someone admitted as a refugee remains a refugee until such time as the circumstances causing them to be a refugee end, or until they find a basis other than refugee status to reside in a county.
So, refugees would continue to be refugees for as long as the war lasts, and for a reasonable time thereafter (as determined by national law) to allow them to arrange for their return to Ukraine once the war is over.
In some cases historically, for example, in the case of many refugees from Afghanistan (pre-9-11), refugee status can last a very long time.
If the war in Ukraine lasted twenty years, people who found no other legal basis for lawful presence in a country would continue to be refugee visa status residents of the country.
On the other hand, if the war in Ukraine ended tomorrow, and circumstances were sufficiently restored to normalcy to allow for the return of refugees to Ukraine promptly thereafter, most Ukrainian refugees would have returned or would be facing imminent deportation to Ukraine quite quickly, perhaps as soon as a year from now or sooner.
There is an incentive for refugees to seek other alternative grounds for legal residency, however, since refugees are often not entitled to all of the privileges afforded to immigrants who are entitled to live in a country on other grounds, and because refugee status ends when the basis for being a refugee ends.
Over time, as refugees live in a country for a long enough time, some of them will find a non-refugee basis to live in a country as a full fledged immigrant so the pool of people classified as refugees will tend to shrink over time. Some refugees will marry citizens of the country where they are living and get visa status that way. Some refugees will enroll in college in the country and get student visas. Some will apply to be non-refugee immigrants based for example on work related skills or employment sponsorship and gain a work visa in lieu of a refugee visa. Some will invest money in businesses in the country to which they migrated and get investor visas.
Sometimes countries that have had a community of refugees live there for a very long time will pass new special legislation providing a path to citizenship or permanent residency for that particular group of refugees. But that kind of legislation is typically not on the books to take effect automatically and comes down to the politics of a future legislature. Some countries have done that in the situations where it has come up, while others have not.
While the E.U. allows free travel within the designated area, immigration is still administered by national governments and the exact procedural and substantive requirements for immigration status in each country is a little different.
Also, the legal citizenship status of children born to refugee parents while in another country as a refugee is not uniform. The majority rule is that such children do not become citizens of the country where they are born under jus sanguinis principles. But, some countries in the E.U. grant citizenship on a jus soli basis to anyone who is born in that country with narrow exceptions and in those countries, the children would become citizens of that country and in some circumstances might even be able to sponsor other relatives to become citizens of the country where the child of the refugee is born.
As illustrated by a lengthy survey of historical immigration policy and politics in New Zealand that also compares the New Zealand experience to that of other developed countries, immigration laws ebb and shift over time in response to shifting national priorities and an evolving international situation. Changes on a decade by decade basis in a country's immigration laws are not unusual. It is not an area of the law, like the law of contracts or property or torts, where settled principles remain largely the same for centuries at a time. It is more akin to tax law or national budgets that is always being tweaked to address current contingencies.