The literal meaning is nearly lost these days when few people, at least in the U.S., get their chicken from any place other than the local supermarket or Kentucky Fried Chicken, but back in the old days when a much larger percentage of the population lived on farms, they kept and slaughtered their own chickens by whacking off the heads.
A chicken with its head lopped off will flop and run around erratically from residual muscle action (or whatever the term is). From this phenomenon comes the metaphor, which seems to be disappearing along with a predominantly rural population.
As a side note, English contains many chicken-oriented metaphors, e.g. "don't count your chickens before they're hatched."