They didn't, but then they did, to the satisfaction of the Viacom case. Napster and Megaupload never built the tools to comply to the degree that YouTube did. Maybe if they had, they would still exist.
Moral of the story- ignore the law for as long as you can and comply hard enough when you have to.
It helps to have zirp levels of investment too.
I think the other issue is that, if Megaupload and Napster actually complied hard, they wouldn't have many content or users left. YouTube may have had pirated content, but it also had enough original content to stand on its own.