You were obviously not there at the time. Bill Gates got rich because IBM signed the daftest contract in computer history from their point of view.
Yes: IBM - the company known for hiring the very best in legal expertise signed away their arms and legs
Why? - I would like to know that!
I don't think it's so strange. IBM didn't expect the PC to be a success. It was a niche project pushed by a few execs over the objections of more -- who saw it as undercutting IBM's real business, to whatever degree it was successful -- and ignored by most of the company as irrelevant. Other parts of the company were actively trying to kill the project. The group developing the PC needed an operating system and needed it quickly. They couldn't take the time to build one, assuming they could find the budget, and likewise couldn't pay a lot of cash up front. Licensing an existing OS for a low per-unit cost was an obvious win.
And, of course, by the time it became clear that the PC was a success, it was too late to change OSes, and by then Gates would've been a fool to sell. Besides, the cost to IBM was low and the machines were selling well. As long as IBM was the only company selling PCs, there really was no significant downside to IBM, and IBM was confident in its legal teams' ability to shut down clones... until Compaq performed a successful clean-room reverse engineering of the PC BIOS.
It ultimately boils down to lack of foresight, that the PC would be so important, and that IBM couldn't prevent clones. Without understanding those, IBM had no reason to insist on ownership of the OS.