A Google Books search turns up two examples of "stick in the mud" used metaphorically in the eighteenth century: an item in The Gentleman's Monthly Intelligencer of December 1733 that lists, as one of 14 "Malefactors [who] receiv'd Sentence of Death" at the end of the December 8 sessions at the Old Bailey,
John Baker, alias Stick in the Mud, for breaking open the House of Mr. Thomas Rayner, a Silversmith, and stealing thence Plate to a great Value.
The other occurrence is from just over a year earlier, from The General Evening Post (November 15–17, 1732), reported in William Walsh, A Handy Book of Curious Information (1913):
George Sutton was yesterday before Justice De Veil on suspicion of robbing Colonel Des Romain's House at Paddington. ... At the same time James Baker was before Justice de Veil for the same Fact. The Colonel could not swear to him, but the justices committed him to the same place with Sutton. George Fluster, alias Stick-in-the-Mud, has made himself an Evidence, and impeached the above two Persons.
It is by no means obvious that George Fluster and John Baker owe their alias to a stubborn adherence to a life of crime rather than to being what we would now call "slow on the uptake." The fact that two people caught up in criminal investigations in London in 1732–1733 were known by the alias "Stick in the Mud" suggests that the sobriquet may have enjoyed a brief vogue; but whether that alias came from the criminals' associates or from their government prosecutors is unclear, as is the precise meaning that Londoners in 1733 attached to it. In any event, I suspect that by the 1830s the expression "stick in the mud" was understood to refer to fuddy-duddies and slowpokes, and not to incorrigible outlaws.
Th rest of Walsh's entry for "stick in the mud" is worth repeating as well:
Stick-in-the Mud. A colloquial expression common to both England and America, and applied to a dullard or slow coach, a person who has never made any progress in education or business or in life generally. An early example of the use of the term in literature occurs in "Tom Brown at Oxford"  by Thomas Hughes. ... It is suggested that the term "stick" applied to an actor deficient in histrionic talent may be an abbreviation of the longer phrase. A famous jest of Sir William S. Gilbert may be recalled in this connection. In allusion to a certain dramatic club the playwright said, "I wouldn't call it a club, but a collection of sticks."
The earliest nineteenth-century instances of metaphorical use that I could find in a Google Books search of "stick in the mud" and "stuck on the mud" involved the latter phrase. Here are the earliest two. From a review of "The Pleasures of Human Life" by Hilaris Benevolus in The Literary Panorama (1807):
Mr. Beresford, who, by the bye, has been happy enough to postpone his new "Miseries" for a time, may congratulate himself, with Falstaff, that "he is not only witty himself, but the cause of wit in other men:" if we had not bad [sic] his "Miseries," we had never had these "Pleasures:" if we had not been "stuck in the mud" in his book, this Mr. Benevolus had not helped us out; if we had not felt Beresford's "wasp at the bottom of our boot," Benevolus had not pulled the boot off: not that this work is the echo of the former; unless indeed we compare it to the Irishman's echo, which when asked, how do you do, Pat? answered, very well, I thank you!
From The Monthly Mirror (July 1808):
Up rose Mr. —————, when Dallas sat down,
And stammer'd and stuck in the mud like a clown.
"Nay give him some law," cried a friend, "and he'll plead—"
"Pray do," said the Judge, "for he wants it indeed!"
In both cases the notion is of being trapped or exceedingly slow-moving (in mind).
The phrase "old stick-in-the-mud" pops up (and flourishes) in the early 1830s. Here are the first three instances that a Google Books search finds.
From William Ellis, "Miru and the Man-Spirit," in Fraser's Magazine (April 1831):
Spirit! pray what are mortals about?
Are kings hunting conquest, or lame with the gout?
Do they see in their subjects their own flesh and blood?
Answer me quickly, old Stick-in-the-Mud!
From "The Simpkin Papers" in The Metropolitan (January 1832):
Isn't he a priest of the real old stick-in-the-mud religion, that was established in Ireland before Orangemen were heard of, and will flourish when they're all drowned in the Dead Sea?
From "Our Birds," in The New-England Magazine [Boston], volume 2 (April 1832):
There is a great, awkward, long-shanked fellow, called a HERON, whom you may see, at times, standing on the shore, or the edge of a marsh, stiff as a poker, demure as a quaker, and, to appearance, most stoically and heroically bent upon doing nothing. Hour after hour you behold him keeping his station immoveable; do not imagine, however, that this moping dunderpate is asleep. Though his chin is sunk upon his breast, though his long neck is doubled up, and lying mightily at ease, depend upon it, old stick-in-the-mud is wide awake; his eye is bent upon the waters, his mandibles are set for a quick snap.
I couldn't find any instance of "stick in the mud" from the nineteenth century involving a situation connected to criminality.
Interestingly (and consistent with Walsh's note that the expression was popular on both sides of the Atlantic), "old stick-in-the-mud" appears in both London and Boston within a 12-month period. John R. Bartlett claims "stick-in-the-mud" as an Americanism in his Dictionary of Americanisms, fourth edition (1877):
Stick-in-the-Mud. (Pron[ounced] stickneymud.) Very common for a slow, inert man; also used for "Thingumbob," "what d'ye call 'em," or a name you can't remember. "Come, old Stick-in-the-mud, and give us a lift."
But despite the term's being "very common" in 1877, the first (1846), second (1859), and third (1860) editions of Dictionary of Americanisms don't include an entry for it.
An entry for "stick-in-the-mud" also appears in Thomas Davies, A Supplementary English Glossary (1881):
STICK-IN-THE-MUD, a slow fellow or bungler. [Example:] This rusty-coloured one is that respectable old stick-in-the-mud, Nicias.—Hughes, Tom Brown at Oxford, ch. x.
Although the evolution of "stick in the mud" is by no means certain, I think that the likeliest path of meaning was from a person literally stuck in mud, to a person too slow-witted to take care of himself or herself, to a person unwilling to get out of a rut and try new things, to a killjoy or party pooper. It is possible, of course, that the "mentally slow" and "stuck in a routine" senses of the phrase arose in parallel from the original "person, horse, or coach stuck in mud" sense.