The story
Attested from 1657.https://www.oed.com/dictionary/son-of-a-bachelor_n Likely a minced oath of son of a bitch based on the assonance between bitch and the first syllable of bachelor, and with bachelor being less vulgar but implying bastardy.
Etymology from Wiktionary, CC BY-SA 4.0.