Molly is a nickname for
Mary because in the Middle Ages some names that had Rs were changed to another consonant for nicknames because the Anglo-Saxons couldn't pronounce Rs very well.
This is how we get
Molly from
Mary, as well as
Sally from
Sarah,
Hal from
Harry,
Dolly from
Dorothy,
Bob from
Robert,
Dick from
Richard, etc.