> How can they pay for something and not own it?
Have you ever purchases software? Any media, recorded performance, or book?
I don't mean to be rude here, but this question shows a complete lack of awareness of the problem space.
There are a number of contributing factors to why most government software is not open source, but here are some of my direct observations as a consultant to government departments, an employee of government departments, a purchaser of products and services at multiple corporations, and a manager of contract software development as an employee of a corporation, and the owner of small business.
1. Stakeholders building software, using either directly employed, or contracted resources, have a desire to develop the software for the lowest cost possible. Generally this means preferring buying over building for many cases, and building on commercial (paid, free, or open source) stacks that promise easier development and efficiency. This often results the project being encumbered by licenses that complicate the potential release of software as open source.
2. Many government initiated software development projects are done directly in pursuit of supporting legislation that is tightly bound to the jurisdiction of the legislation; even if the legislation is meant to ratify state/provincial, federal, international or other standards, laws, and regulations, there will be regional variations that require at minimum configuration, and most likely real code changes to meet requirements. This often results in software that is tightly coupled to a particular jurisdiction in terms of both legislation and regulations, but also in terms of the ecosystem the software is developed in. The encumbrances created by these couplings often have dependencies on closed and proprietary systems which is a great deal of friction for releasing open source projects.
3. Despite the passage of many international rules related to economic development agreements like the former NAFTA and the newer USMCA which provide provisions to allow fair competition for government contracts within the regions affected (and I believe EU and other trade blocs have similar legislation), the opportunity to award software development contracts to local firms (at any level of locality across municipal, state, and federal jurisdictions) is a strong temptation for politicians to curry favor with voters and business communities. This is often pitched as economic benefits by creating jobs locally, while bolstering local businesses and making them more competitive; if these projects are subsequently released as open source projects, the perception from decision makers is that the value of the investment in the local community is lost. This is where a significant opportunity for what you bill as corruption is identified - I haven't seen a procurement process in government that can't be subverted by suitably motivated buyers and sellers.
4. Releasing open source software can be a public relations nightmare - bug reports, public review and criticism of design or implementation choices generally land on the desks of whatever passes for a service desk for that jurisdiction, who are usually ill equipped to deal with these technical issues, and also are generally understaffed for their core responsibilities. Eventually those reports and criticisms make their way up through different paths and land on the desk of high level bureaucrats and elected officials, who then have to deal with these issues as public relations items. Have to deal with HeartBleed2022? If it's internally developed and open source, the buck stops with the politicians and how they let it happen, time for a public inquiry! If it's an off the shelf product, "We are disabling the service until a patch becomes available." [1, specifically log4j] , and people can grumble about purchasing choices, but it's much harder to criticize the actual implementation.
Alot of folks in government (including me when I was there) wanted to release our stuff as OSS, but there is only so far you can go with opensourcing modules that depend on SAP code, IBM code, or systems that are supplied by the federal government.
[1] https://www.canada.ca/en/revenue-agency/services/e-services/...