A lot of old nicknames don't really make a lot of sense at first glance. The short answer is rhyming slang, and the long answer is there simply used to be a lot less names in English that were acceptable and commonly used. So, for instance, Richard being shortened to "Rick" is pretty straightforward, but you probably knew several Richards and Ricks, and you want to call them different names. So instead of Rick, you call them by a rhyming nickname, in this case "Dick." The same is true of "Rob" being short for "Robert," but "Bob" was too. Because "Bob" rhymes with "Rob".
One of the oddest in this vein is Peggy, which is short for Margaret. Because Margaret would get shortened to Meg, and then rhymed with Peg, and then somehow lengthened back again to Peggy. ¯\_(ツ)_/¯