Realistically most ships between the 1600s and 1700s carried cargo mostly not gold, so what did pirates do with all those random assortments of wheat, cotton, tea, and stamps?
There were black market merchants, smugglers, counterfeiters, and launderers of goods that they could sell it to. Smuggling probably being the largest one. Not every port was secured or had a harbormaster who cared (bribed) enough against pirates sailing in to sell their goods. If it was, pirates could offload their goods ship to ship or at a beach site, to a more legitimate seeming ship or a smuggler. For goods that did not have any system in place to verify their source, they could simply be sold to any seedy merchant. For goods and ports that were controlled, a more sophisticated system would be needed. The process being sort of similar to modern day money laundering or cigarette smuggling. Pirates takes possession of the goods, then they must get it in condition it can enter the legal market or find a black market buyer. This was usually done by a 3rd party counterfeiter, forger, or merchant. The goal being either to a final consumer who was willing to accept it as black market, or to make it appear legitimate for a consumer who only wants a legitimate good. Piracy was only a small part of the capture/transportation of illegal goods. Many illegal goods began legitimate or were stolen, and became illegal simply because they were smuggled to avoid taxes and duties (or in some cases, only a select few had the rights/privileges of trade).
The respective nations were not incompetent and enacted a plethora of measures to combat both piracy and the trade of illicit/pirated goods. Even in days before electronic monitoring, UPC codes, etc, a lot of goods required stamps, marks, and certification from both goods and merchant. Some measures were somewhat counterproductive, like Spain's mercantilism policies which meant the colonies could only trade with Madrid. This created a black market demand for other European goods.
For some periods there were some less than lawful ports like Nassau and Tortuga which served as pirate havens and markets for illegal goods. More ports fell into a more grey area, where most was legitimate, but some illegal goods were traded. Many more towns and ports were known for smuggling than outright piracy. Cawsand, England was one of them. As time went on and the bureaucracy expanded and the nations and companies had more resources and funds at their disposal they were able to chase pirates out through force and inventory controls.
The actual process of smuggling, mercantilism, and the combating illegal goods would be a large response to questions on their own.
Sources:
Transportation Act 1717
Piracy Act 1698
The History of Pirates Dr. Angus Konstam
Under the Black Flag: The Romance and the Reality of Life among the Pirates David Cordingly
Smuggling: Contraband and Corruption in World History Alan Carras
http://www.oxfordbibliographies.com/view/document/obo-9780199730414/obo-9780199730414-0077.xml
http://americanhistory.oxfordre.com...9329175.001.0001/acrefore-9780199329175-e-263
http://www.oxfordbibliographies.com/view/document/obo-9780199730414/obo-9780199730414-0197.xml