Often a surname as a middle name came from a female ancestor.
My middle name, and my dad's, is my grandmother's maiden name, my grandfather's was his great-grandmother's maiden name & other grandfather's 1st name was his mother's maiden name.
My husband's family has used the name Ross for 8 generations and is comes from an ancestress Elizabeth Ross.
Sometimes a name comes into family through marriage. A relative of my father's given names are John L. Clarke- called John L. for a childless uncle & the Clarke for uncle's wife's maiden name.
However, sometimes a surname can be for someone like a minister, doctor, local landowner.