The name is a slang nickname, the exact origins of which are not conclusively known.
One possible origin is the way that a rat is attracted to rat poison like a child to candy, another possibility being the use of actual candy, particularly chocolate, as bait when luring a rat into a trap that will lead to its imprisonment or demise.
[1] According to United States Environmental Protection Agency statistics, approximately 13,000 American children were treated for ingesting rat poison in 2004, most mistaking the rodenticide for candy.
[2] Warfarin, an early rat poison, was derived from licorice.
Tales of poisoned candy also abound in urban legends.