It's the same reason why kids (used to?) love cowboys and gunslingers. The job description of a cowboy isn't very sexy, it's a cow herder for crying out loud! And gunslingers are about the same as pirates. Yet the romantic movies of the fifties to eighties are responsible for those misty-eyed depictions of heroism and adventures. Hmm, Indy is an archeologist...
Back to pirates: There were pirates which were tolerated or even encouraged by governments called corsairs or privateers