The Avengers 2 just hit China yesterday. The official translation of the line "If you get killed, walk it off!" is "Someone is trying to kill you, run, run for your life" (This is the English version of that Chinese translation). Such a nonsense. But how to understand the original English sentence correctly?
"Walk it off" is a flippant response for when someone is hurt or injured. It generally means that they should continue as if nothing had happened (that is, they should continue walking), and that they'll be back in good health after a while. An example might be if you took a bad step and hurt your ankle slightly; it may well be better to continue walking until the pain subsides instead of stopping.
In the Captain America example he is joking that even dying should not stop you from winning; you should pretend that nothing happened and keep fighting.
When one is injured, for example in an athletic competition, the advice might be to get up and walk around in pain until the pain subsides and one is again able to participate. This is opposed to one's probable inclination to lie on the ground until one feels able to continue. "Walking it off" is seen as a tougher and perhaps quicker way of dealing with the injury.
Being killed, here, is treated just as any other injury, as if it were possible to recover from death.
I suppose you could translate into a Chinese sports analogy (as this one is most applicable and familiar in the context of American football). Perhaps "If you get killed, keep swinging the ping-pong paddle!" would suffice.
The implication of "walk it off" is not just ignore the problem and hope it gets better, but instead that the walking will actually be beneficial.
For example, in baseball, if someone is hit in the leg by a pitch is is much more reasonable to say "walk it off" than if they are hit in the arm or head.
For an older example, there is the 1736 play Eurydice Hissed, or a Word to the Wise:
[Mr. Emphasis]: Why, faith, Jack, our Beer and Beer sat but ill on my Stomach so I got up to try to see if I could not walk it off.
[unnamed character]: I wish I had any thing in my stomach to walk off...
I wish to re-iterate Jander's comment. "Walking it off" is sometimes actually better advice to an injury that isn't too serious. Sometimes getting up and walking will produce circulation, and keep the injured area warm and limber. If the area of injury is left to stiffen up, then the inflammation may get worse, and the injured party will continue to focus on the injury, which may increase suffering, possibly creating even more tension and inflammation.
My recollection is that, as a child in the '70s, usage was generally more literal, with 'mates trying to accurately evaluate whether walking it off was truly the better remedy. Over time, humor seemed to take precedence, and nowadays I usually only hear it used sarcastically.
OED says to walk off is to "to get rid of (the effects of liquor, an ailment) by walking exercise."
To add to the other answers giving the sports analogy where one "walks off" an injury (which incidentally is also used to show the officials that one will shortly be able to resume play), this could be a fan shout out.
Death in the comics is something that you might just "walk off". I can't find the issue right now, but when Rick Jones was trying to bring back his dead girlfriend, he asks a group of people "Who in this room has been dead before?" with everyone present raising their hands.
EDIT: I asked about this issue on scifi.stackexchange and thanks to Richard I have an answer.
If you have ever been slammed around whether in a fight or something like a car wreck... then you may have been dazed. Walking around is like 'getting some fresh air' in that it can help you feel better. Moving around is better than just crumpling where you are... and may help you 'get it back together'. Of course, this is a joke because if you are killed 'walking it off' will not be an option...
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.
To "walk it off" is an idiom from American baseball. For instance, a batter fouling a ball of his foot might be told that. Here's an example: