The story
From legal + beagle. Beagle was probably chosen for the rhyme and because beagles were traditionally used for hunting hares or rabbits, due to their keen sense of smell and tracking instinct. Compare legal eagle.
Etymology from Wiktionary, CC BY-SA 4.0.