Something about taking prostitutes on voyages across the sea in the olden days. You’d romance her under the cannons and the bastard child would be a “son of a gun”. I don’t remember where I learned this so feel free to correct me if I’m wrong.
Edit: I looked it up and got some details wrong, but pretty close
Mysterious Ways ™️