Okay Phil, because you asked
I'll explain this as delicately as I can. The old sailors, after being at sea for weeks or months, would get very lonely. When they got into port they would find a, um, friend, and take her back to the ship. But sometimes it got crowded on the ship, what with so many sailors having so many friends over, that they had to, um, entertain on the deck, between the guns. Well, accidents happen, and a person who had the misfortune of being conceived in this fashion would be, of course, a "Son of a Gun." And now you know the rest of the story.