It is related to other means of social control that arise in communities, such as charivari,riding the rail, and tarring and feathering.
From the en.wikipedia.org
Some village charivari included dancers dressed as wild men, to represent demons, who were ceremonially captured and symbolically burnt to appease evil spirits at harvest or planting time.