Easy to replace the old version of Linux? Not so easy. We still have customers running SUSE 6.0, because the software they rely on was written for that Kernel and they are unwilling to pay the supplier for an upgrade to a newer version.
Likewise, Linux used to run on a 386 with a couple of MB RAM as well. Good luck getting Ubuntu on anything that small or with a processor with that architecture.
The core of Windows XP was developed before the Internet. And due to poorly written 9x software, they couldn't turn on the security it did support without breaking everything. Because people carried on using Administrator accounts, the situation didn't improve for a long time. Plus you are talking about millions of lines of code written by humans! Even a short story published to Amazon is going to have lots of spelling mistakes, heck living in Germany I look at some of the translations that are done to classic novels and I can only shake my head at the mistakes and inconsistencies in translation that some publishers make. Computer code is a lot more complex. You will never get it 100% bug free and 100% safe, not in our lifetimes - unless you manage to find an infinite number of monkeys and can convince them to work on XP instead of Shakespeare...
And if it were the case, that the OS had to be 100% bug free before it could be released, we would probably still be using MS-DOS or we might have made it to Windows 3.1. Linux would also still probably be awaiting its first "stable" release. Code is made to the best standards we can and at some point somebody has to take a decision, "is it stable enough, good enough to be released?" The same goes for most industries, just look at the number of car safety recalls, cars are death traps and should never be let on the road!
Unlike putting safety features in cars, after all, no physical parts that are made of metal that costs money are involved.
So all those thousands of programmers working at Microsoft to fix the bugs and come up with new methods are working for free?