Common in movies, radio and TV from the '30s and '40s when most harsh words were forbidden. Responding to an insult, getting ready to fight.
I suspect the Why is unnecessary in modern times when a different set of words is taboo. Similar sentences now start directly with You.
But how did Why become the specific introduction to a punch? It doesn't have any semantic content. Maybe it's just the nearest writable word to the roar/grunt that occurs more naturally in the situation? Something like our attempts to put words on the predictable sound sequence that precedes a catfight? [See "Oh Long Johnson."]
I can't pinpoint the last time I heard it, but am pretty sure it's current - 'Why, that's something,' 'Why, thank you, ' 'Why, this junk food tastes good,' anything. And it can be slow and deliberate like, no exclamation mark.
"Why" is usually a question, but in this usage it is an exclamation. I suspect it has little relationship to the "why" that is used as a question mainly because it is pronounced differently. In the exclamation, the "H" is not heard. It sounds like "wy."
What I just wrote is what I already knew but I decided to try a little research on this and found that Google has a hard time handling "why" as anything but a question. I entered "why etymology" and the results were all sites telling the benefits of etymology rather than the etymology of "why." So I failed to get a history of the word.
As for frequency of use, I have never heard it frequently used in everyday language, but my life doesn't go back to the 30s and I was only born in the 40s. But I do hear it in movies regularly. Less in newer movies than older.
The Online Etymology Dictionary gives no separate etymology for the interjection use of why, but it does treat it as a separate use: 'As an interjection of surprise or to call attention to a statement, recorded from 1510s." why Most dictionaries also list this separate use of why to indicate mild surprise. Some appropriately add other sentiments to its use, such as indignation.
So we know when why, but still not why why or how why.
I can speculate, but have no evidence. This use of why seems mostly to occur as a response to someone's words or actions. Perhaps it originated in question: "Why [did you do that], you dirty rat?" On the other hand, you might have, "Who's at the door, Mabel?" "Why, it's John!" Doesn't fit my scenario at all. Unless…" why, [but] it's John." Probably a fool's exercise.