We don't know.
There is no official explanation as to why both different events have happened. We can only theorize. As the other answer says, Jack may have won the compass twice, but I disagree (as that would seem to imply he betrayed the compass before, which would have released Salazar before).
From the wiki:
Jack Sparrow's compass was an unusual navigational instrument most notably used by Captain Jack Sparrow, which he bartered from the voodoo mystic Tia Dalma and later inherited from his captain.
We can theorize, however...
A more logical explanation in my opinion, is that he bartered the compass for his captain, not for himself. In other words, the compass was only his after his Captain's death, when he actually inherited it. Previously, he bargained for it in his captain's behalf. It seems to fit quite nicely with the story, leaves some leeway as to why his previous captain wanted it or cursed Salazar with it, and works well with both perspectives of the story.