The idea of pirate treasure derives from a single incident involving William Kidd in 1699. Kidd was about to be arrested, but before confronting the authorities he buried his treasure on Gardiners Island. He first asked permission to John Gardiner, the island's owner, who later handed over the treasure to the authorities.
This is the whole history of pirate treasure. It inspired Robert Louis Stevenson's Treasure Island, which almost single handedly created the modern image of pirates.
Source: How To, by Randall Munroe