Microsoft is a for-profit company. They have attracted a lot of projects to them by giving away free goodies, like an immense amount of computing power for CI, and over the years have increased the amount of stuff you get for free. (Not long ago you had to pay for personal private repos …) By continuously sweetening the deal for smaller users, then getting orgs to pay once they start needing collaboration features, GitHub built up over a billion dollars in revenue per year (as of 2022).