"fellow, lad, man," 1550s, rhyming nickname for Rick, short for Richard, one of the commonest English names, it has long been a synonym for "fellow," and so most of the slang senses are probably very old, but naturally hard to find in the surviving records. The meaning "penis" is attested from 1891 in Farmer's slang dictionary (possibly British army slang). Meaning "detective" is recorded from 1908, perhaps as a shortened variant of detective. As a verb, "to bungle; to waste time," also "to cheat, treat badly," by 1969, American English (often with off or around).
The story of Dick Whittington's cat is an old one, told under other names throughout Europe, of a poor boy who sends a cat he had bought for a penny as his stake in a trading voyage; the captain sells it on his behalf for a fortune to a foreign king whose palace is overrun by rats. The hero devotes part of his windfall to charity, which may be why the legend in England has been attached since 16c. to Sir Richard Whittington (d. 1423), three times Lord Mayor of London, who died childless and devoted large sums in his will to churches, almshouses, and St. Bartholomew's Hospital.