Question: why peggy nickname for margaret?
Answer: So that gets us Meg. From there, Peg is straightforward: It's a rhyme. The shift from something like Magge, Megge, or Pegge to Maggie, Meggie, or Peggy comes in the 16th C with the Great Vowel Shift — what used to be an unstressed schwa sound shifts to \ee\.