In the story “The Poacher’s Wife” written by Eden Phillpotts and published in 1906, the reference to “swing for him” is made and references being hanged for a crime against the character, Henry Vivian:
I’ll pay him well for his bananas, and I’ll pay him better for something else, which is to help me against that young bloodhound, Henry Vivian. I don’t care what I do against him, for he’ll ruin me if he can ; and if I was guilty I’d say nought, but I’m innocent. And if I’ve got to swing, I’ll swing for him.
The New York Times ran a story on September 15, 1895 entitled “Jim Talbot To Be Tried For Murder Done Fourteen Years Ago: Tracked By His Victim’s Brother.” It was to be a famous trial for murder held at Caldwell, KS with a number of interested parties, from curious spectators to vengeful adversaries, attending. The article read in part:
Were it not for the hounding of John Meagher he would get free, so many years having elapsed since the tragedy, but the twin brother of the dead Mayor of Caldwell swears that Talbot will either swing for that or that he will shoot him on sight if the man is released.
The first published version Idiomation could find was in a copy of The Lady’s Magazine, published 1787. The reference comes in the dialogue of a comedy called The Embarrassed Husband:
“Murder him? No, no – it is not worth while to swing for him.”
And so whether someone is willing to “swing for that” or “swing for him” or “swing for her” the meaning is clearly that the person in question is willing to be hanged for a criminal — or perceived criminal — act they are about to commit.