The name Richard is very old, although its origin is disputed. Richard and Ricard were equally popular in the Middle Ages, and the abbreviations led naturally to diminutives—such as Rich, Richie, Rick, and Ricket. Rhyming nicknames were also fairly common in the 12th and 13th centuries, and so we also have Hitch from Rich, Hick and Dick from Rick, and Hicket from Ricket.
The name Dick (like the name Jack) was used colloquially to mean a man or everyman. The expression “every Tom, Dick, or Harry” attests to the this as a long-established usage; Shakespeare uses “every Tom, Dick, or Francis” in Henry IV Part I. Many other usages. The Oxford English Dictionary cites a dick as meaning a type of hard cheese in 1847, which lead to the usage of “spotted dick”. The term “dick” was also used to mean a riding whip, an apron, the mound around a ditch, and an abbreviation for “dictionary” around 1860.
Dick also meant a declaration, in which sense the OED cites someone writing in 1878 “I’d take my dying dick” to mean “I’d swear a dying declaration.” The term “dick” came to mean policeman around 1908, and then detective.
The use of “dick” as coarse slang for penis first arises around 1890. Tracking the history of uncouth words is not easy, since such expressions were not generally written down. How “dick” came to be associated with penis is not known, although the riding whip may have pointed the way.
Source