It is enshrined in their constitutions, which are pretty recent.
Article 11 Italian Constitution:
Italy rejects war as an instrument of aggression against the freedom of other peoples and as a means for the settlement of international disputes. Italy agrees, on conditions of equality with other...
Source: Ukraine refugees given right to live in EU for three years
Here are two interesting perspectives on the treatment of Ukrainian vs. other war refugees by the EU and its member states:
Help for Ukraine's fleeing refugees shows the power of support when the political will is there...