I know that pirates had port cities like Nassau and Tortuga to flock to, but how did those communities operate? Did they elect their own governors and have laws in place to keep the peace, or was it anarchy? How did these communities sustain themselves? Did pirates bring back loot and share it with the community to keep it running, or work together to generate more profit from their pirating?
This is a topic that I think deserves more attention in academic pirate work.
I think the best way to answer this question (for Nassau, or New Providence in the Bahamas) is to go straight to the primary sources. Here is Thomas Walker, former governor of the Bahamas still residing in said Bahamas in 1715.
"Accot. of Piratts and the State and Condition the Bohamias are now in Rendered by Thomas Walker" New Providence. March 12, [1715]. [Note that I am not correcting period spelling - back then spelling wasn't standardized]
"...And Whereas the Inhabitants of Ileatheria [Eleuthera] never Took upp Lands by pattent nor pay any Rents to the Lord proprietors for Liveing on their Lands And that the Said Inhabitants are some of them Guilty of Committing piracy and fitting out pirats and receiving and Sheltering them, and the goods they Rob the Spaniards of are Traded with and sold to English Shipping, and the Brasilletto Wood by them Cutt off their Lordshipp's Lands is most Generally carryed to Querasaw [Curacao] and Cape Francesway [Francois?] whereby the Lawfull English Trade is retarded and the King's Customs Diminished. It is Therefore hoped, by the Inhabitants of Providence That His Grace the Duke of Beaufort Pallatine and the rest of the Lords proprietors of the Boham Islands [Bahama Islands] will give unto the next Governor they send an Instruction to Command all the Inhabitants from Ileatheria to Settle and Strengthen Providence..."
Another Thomas Walker account:
[Thomas Walker?] to the Council of Trade and Plantations" South Carolina. August [?] 1716. CO 5,1265 no.52.
"...I was formerly directed by H. E. Genll. Nicholson to render to your Lordships an accot. of the state and condition of ye Bohamia [Bahama]...those Islands open to be a recepticall and shelter of pirates and loose fellows and gives ye inhabitants as well as ye trading vessuals [vessels] from other parts [interlopers & receivers] ye liberty and opportunity of inriching themselves by sideing and dealing with, entertaining and releiveing such villians who from time to time resort there to sell and dispose of their piraticall goods, and perfusely spend wtt [what] they take from ye English French and mostly Spaniards, and as I am an inhabitant of New Providence have bin an eye witness to those ellegiall [illegal] and unwarrantable practises committed both by ye pirates and inhabitants and others tradeing there...The pirates daly increase to Providence and haveing began to mount ye guns in ye Fort for there defence and seeking ye opportunity to kill mee because I was against their illegall and unwarrantable practices and by no means would consent to their mounting of guns in ye Fort upon such accots [accounts]..."
I wouldn't say it was anarchy in Nassau and the Bahamas, since individual pirate captains contributed leadership and organization to things, to the point of re-fortifying the old fort there. There was some order, enough that merchants could illegally trade with them. If I remember correctly, there was a "mock" governor put up in Nassau for a time, but that was more or less a joke towards authority it seemed. The community sustained itself by taking the plunder obtained from pirated ships and selling it illegally to colonial merchants who got it for a fraction of it's actual market value (since the pirates wanted profits and since they had not much of a overhead cost for obtaining said stolen goods). The merchants provided supplies and other things in exchange for the cheap goods. There was no commune style approach to things, and the working together was often informal while in port (they shared a port to get supplies and entertainment, and sometimes agreed to do things to keep the place safe, but not much beyond that), though on occasion two pirate crews may join together at sea and raid together. As far as I can tell, there were no official laws, maybe just some common sense unspoken ones that mostly revolved around who had the most strength and influence at the moment.
I would highly advise reading The Republic of Pirates: Being the True and Surprising Story of the Caribbean Pirates and the Man Who Brought Them Down by Colin Woodard for more information on this (it's where I got a lot of my information, and helped me find the primary sources for myself).