Example here in clip from Star Trek: First Contact at 0:45. I’ve seen it elsewhere in tv or movies, never in real life that I recall.
It’s just a random physical reaction to the strength of the liquor. I’ve seen whiskey newbies hit their thigh with their fist or kick out their foot when they swig too fast, as a comparative example. In this case it’s played up for comedy.
There are similar reactions in various performances by The Three Stooges - there’s one near the end of this video that is quite similar (although played up for comic effect):
I expect this is a continuation of a vaudeville or music-hall precedent.