I thought it came from when children were given the same names as their parents, boys in particular, and the middle name was used to differentiate between the two. Apparently it also used to be common before double barrelled last names for children to be given their mothers maiden name asked a middle name. Both my grandmothers had this and my dad's middle name is his my granny's maiden name.
We gave our eldest a name derived from OHs and then his middle name was my dad's name, which is also FILs middle name.
This time around we've just picked two names we like that have no family connection.