I recently voted to close a question that asked about the origin of the phrase "walk it off"—and the grounds given for closing that question were that it was a duplicate of this question and had an answer here. Under the circumstances, I thought I should provide an answer here that specifically addresses the question of when "walk it off" originated, and what sense or senses it had at that time.
In Google Books search results, the two earliest instances of "walk it off" occur within five years of one another, in books written by Henry Fielding and Samuel Richardson. Th earlier is Henry Fielding, The Historical Register: For the Year 1736 (1737):
1 Player. Mr. Emphasis, good-morrow, you are early at the Rehearsal this Morning.
Emphasis. Why, faith, Jack, our Beer and Beer [in later editions, beef and beer or beer and beef] sat but ill on my Stomach, so I got up to try if I could not walk it off.
1 Player. I wish I had any thing in my Stomach to walk off ; if Matters do not go better with us shortly, my Teeth will forget their Office.
This is the same instance that DavePhD quotes in his answer, although he identifies it as being from Eurydice Hissed, a companion play to The Historical Register. Here, the walking is done in hopes of settling an upset stomach due to indigestion.
From Samuel Richardson, Pamela (1740):
I had the Courage to take hold of his Arm, as if I had like to have slipt; For, thought I, thou shalt not see the Girl, worthy Friend, till I have talk'd to thee a little, if thou dost then.—Excuse me, Mr. H.—I hope I have not hurt my Foot!—I must lean upon you.
Will you be pleased, Madam, to have a Chair? I fear you have sprain'd your Foot—Shall I help you to a Chair?
No, no, Sir, I shall walk it off, if I hold by you.
Here is the more familiar (today) sense of walking off the effects of an injury or physical mishap. A similar instance appears in Jean-Baptiste Louvet de Couvray, Narrative of the Dangers to which I Have Been Exposed, Since the 31st of May, 1793 (1795):
I purposed to have pushed on much farther ; but I had not advanced above a mile, before I felt about my left heel an acute pain, which struck me at once like a flash of lightning. Hoping it would come to nothing, I endeavoured to walk it off: it became more acute, fixed, and extended under the sole of my foot. Probably it was an inflammatory humour, forming in consequence of my checked perspiration, which had been thrown upon my lungs at the moment when I fainted at the door of that woman, and which my late exertions had determined to the extremities.
To conclude, it appears that "walk it off" already had its still-current literal meaning of "walk in order to recover from some physical complaint, malady, or injury" in its earliest Google Books matches, from 1737 and 1740.