Because "nation states" are not one making decision either. It's done by one specific career bureaucrat or group of them and even best of people who work on such positions usually choose it because of job security and stability.
Spending 10x more on IBM or Palantir can't get them fired, but trying to build something in-house their organization don't have competence for can get them fired.
And this is even if you don't take lobbying or corruption into account.
> It's done by one specific career bureaucrat or group
Almost all governments have a legally defined public procurement framework. If this is overridden, it's pretty much always by elected politicians, not by regular government employees.
Also it's not like 4 years ago either UK or EU governments would expect they will soon want to get rid of all US companies in their public sector.
Yes, and: often they're prevented from building it in house!
In some countries yeah. In UK almost all of gov.uk even hosted on github with public commit history.
But its kind a obvious why some system for refugees was outsourced for consultancy.
The GDS is one of the more credible parts of government IT in the UK and IME generally well respected. The government websites and online services have largely been well done. But there are limits on how much that organisation can take on with the resources it has and it's still subject to the same challenges around compensation and working environment I mentioned in another comment that make it difficult to hire and retain good people. Unfortunately it's not realistic to build all government IT projects in house that way at the moment.
As far as I get it GDS cant just build things fast for the reasons you mention and refugee situation look like reasonable one to outsource it.