Tribolectric charging, like a Van de Graaff Generator (The birthday present from Lafayette Electronics that my mother returned when reading 20,000 volts on the box)
https://en.wikipedia.org/wiki/Triboelectric_effect
Materials from either end of the scale build the largest charge, in your case hair/skin is at the positive end, flannel is likely polyester or similar, at the negative end of the scale.
Wearing leather (at the same end of the scale as hair/skin) would be less 'shocking'