In Treasure Island, Captain Billy Bones' exclamation "comes to swinging, swing all, say I" is an abbreviation of what was then a very common idiom normally in the form "to swing for something," which is an idiom describing the punishment of criminals by hanging, or swinging, from the gallows. The idiom may also take a nautical twist in the form "to swing from the yardarm," since according to pirate wisdom, the yardarm was a favorite place to hang enemies or prisoners.
In light of this information about the idiom "to swing for something," the meaning of Billy Bones' remark becomes more clear. While we can only guess at what was said between Billy Bones and Bad Dog (sine Jim Hawks couldn't hear, we too are left in the dark), it would seem that Bad Dog was by some means trying to threaten Billy into revealing what Bad Dog wanted and that the threat included some reference to being turned over to the constabulary authorities (police) who would surely punish his crimes by death by hanging; picture Bad Dog saying something like "You'll swing fer it, Billy, you will. You'll swing fer it."
Since Billy Bones was not alone in the piracy that was his livelihood, because pirates all work as a group and share the bounty, Billy's response to Bad Dog is to remind him of the collective nature of piracy, which in Billy's mind deserves a collective punishment by death. This is what prompts him to say and what he means by saying, "If it comes to swinging, swing all, I say!"
With all this information at hand now, it is more clear that a paraphrase of Billy's words would be: "If it comes to being hung from the gallows for crimes, we all will hang together, I say." Undoubtedly, if Bad Dog had tried to turn Billy in, Billy would have produced evidence or testimony by which to convict the others including Bad Dog, so that not just Billy would swing from the gallows, but all the pirates would swing.