This doesn't happen in the corporate world (as much) because of various factors such as tax incentives and market pressures, but would be much more likely in the stately world of government IT.
A better solution would be license the code, such that it could not be used to provide public services unless the governing body contributed to a development association (either in money, code contributions, or some mixture thereof).
Only societies starved of ideas other than lowest common denominator free-market thinking. In reality societies choose to do the thng that cost money, for no other reason than that they want the outcome. We do tons of things for no specific (short term) gain. Some would say that this is what sets a great civilization apart from the rest.