In the absence of a time machine, these are guesses.
Margaret: shortens to
Maggie very easily. If you're bored or playful,
Maggie can morph into Meggie. Once that's done, all you need is a sibling with a bad cold (this is the UK we're talking about, back in the Middle Ages probably) and you get
Peggy.
Molly and
Mary: I also detect the presence of a sibling here. R sounds are notoriously difficult for children, so
Molly could be their best attempt at
Mary. And it took on a life of its own and, same as Meggie, morphed into
Polly.
Jack, or
Jock in Scotland, = Johnkin = little
John, like a lambkin! And it got shortened.
Bob and
Bill also seem to be likely mistakes made by the very young; babies and toddlers find /b/, /d/, /p/ and /m/ easy to say (think baba, dada, papa, mama ...). Parents think this is cute, and perpetuate it.