Nazi mistress punishment. SPOILERS
I have observed in many movies and read in many books about the usual punishment for women who fraternized intimately with the Nazi's during the WW2. This always consists of cutting or shaving of hair and in certain cases they even get tar applied to their head. Gilda and the other lady in the movie get their hair cut off. Another ready example can be found in the movie Malena.
This type of punishment seems to have been universal. What is the origin of this punishment? I am sure that it was not decided beforehand to impart this kind of punishment, but a spontaneous action. I guess it must be based on a historical ritual. Can anyone shed light on this?