So, I'll bet not too many of you knew about the supposed nautical origins of this saying. It is said that during the period of time that the Royal Navy allowed women to travel on their ships that a child born of questionable parentage was born as a son of a gun. A child reared on the gun deck was also referred to in this manner. An early quote seems to support this theory.
Admiral William Henry Smyth wrote in 1867, Son of a gun, an epithet conveying contempt in a slight degree, and originally applied to boys born afloat, when women were permitted to accompany their husbands to sea; one admiral declared he literally was thus cradled, under the breast of a gun-carriage.
You have to love nautical lingo and lore.