This quotation is uttered by the captain Billy Bones (Chapter II, "Black Dog Appears and Disappears") during his loud and eventful meeting with the mysterious Black Dog. Missing two fingers on his left hand, Black Dog also appeared to be lacking the sailorly look that most seamen had who entered the Benbow Inn. Neither of the men appeared to be happy at seeing the other, and soon their voices rose in argument.
For a long time, though I certainly did my best to listen, I could hear nothing but a low gabbling; but at last the voices began to grow higher, and I could pick up a word or two, mostly oaths from the captain.
“No, no, no, no; and an end of it!” he cried once. And again, “If it comes to swinging, swing all, say I.”
Immediately afterward, Jim heard the "clash of steel... and then a cry of pain," and the bleeding Black Dog came running from the inn. Billy Bones followed hotly at his heels, swinging his cutlass again, but instead striking the sign above the inn, leaving a "notch on the lower side of the frame (that can be seen) to this day."
No doubt when Billy Bones threatened to "swing all," he meant more than just his fists: He meant to fight with his swinging steel cutlass as well.
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.