Well it depends on how you look at it.
If you just consider ninja an assassin, I think ninjas predate pirates, but then again, pirates have been raiding the seas since the start of naval trading, i.e. at least probably 1,000 B.C., whereas ninjas as in Japanese experts in spying and killing dudes with extreme cruelty and awesomeness, they've been about since I guess 600-700 A.D.? And pirates in the sense we regard it, that is, buccaneers, emerged in the 16th century with Spanish gold fleets.
Pirates, as soon as in the 17th century already, were subject of romantic stories. Ninjas became popular with 19th century romantic wave, along with other Middle Eastern and East Asian themes. Ninjas and pirates in modern originally children's popular culture: ninjas are older I believe.
If somebody knows better please let me know! Umm, I mean, I be believin', if somebody be knowin' better and so on, arr!