Pirates actually rarely bury treasure, despite what the novel “Treasure Island” tells you, as treasure that’s buried meant treasure that’s not spent on more grog and gambling. It was a very iconic imagery though.
The idea probably originated from “Captain William Kidd”, a pirate who actually did bury his treasure. He intended to use the information of its location as a leverage to escape trial and punishment for piracy when he went back to England. Unfortunately nobody bought it, and he perished along with its location.