The story of 'hacker' is not quite the same as the story of 'pirate'. I think that 'hacker' first meant someone who can hack things up, then some people did some hacks to crack systems; to crack a system you had to be resourceful, you had to be a hacker to be a cracker. These crackers made so much of a name for themselves that most people use 'hacker' to refer only to this subset of hackers.
On the other hand, the original pirates were thieves. We are currently seeing a resurgance of the use of 'pirate' to refer to a thief on the sea. So the word always referred to something negative.
So 'hacker' was a positive (or at least neutral) term, and it got its negative reputation by being associated with people who did bad things. 'Pirate' was negative, and some people tried to give other people a negative reputation by calling them that.
In summary, 'hacker' got its negative connotations from bad people, but 'pirate' is a negative word that is used to give a negative reputation to people.