They are doing it, but there's no profit incentive. Github is a bit of a special case because of their commitment to OSS and the broader engineering community, but the moment a downturn occurs and MS takes a harder look at P&Ls, you better believe that's on the chopping block.
The public sector is exactly where you need things that are important to society but don't make money.
There's a profit incentive: GitHub sells its services. The free stuff is an advert.
At any rate, even if they give it away for altruistic reasons, Microsoft is a sustainable going concern that brings in more than it spends. It can afford charity. The US government isn't and can't.
The public sector is exactly where you need things that are important to society but don't make money.