In its earliest incarnations, more primitive shadows were used to represent spirits, the presence of gods and were sometimes facilitated by Buddhist shamans. Since the birth of formalized shadow puppet performances, the art form has evolved in tandem with religion in China. In periods and dynasties where religion, spirituality and superstition were ostracized, so were the performances.
Throughout the last millennium, shadow puppet performances have been central to religious festivities in nearly all parts of the country including religious holidays, birthdays of deities, ceremonies for good harvests, house clearings (of bad spirits) and exorcisms of plagues or bad luck. These performances were funded by the community itself and were open to all.
Privately, shadow puppetry has also been a central element in personal celebrations of birthdays, weddings, funerals, house-raisings and more and were usually funded by the family hosting the event. At these performances, invited guests of the family would enjoy a show alongside a grand meal and other activities.
With the constraint of religious activity during the Communist Revolution shadow puppetry still struggles to find relevance in the new secular culture.
For further reading on Chinese Shadow Puppetry and Religion, check out Fan Pen Chen's excellent book Chinese Shadow Theatre: History, Popular Religions and Woman Warriors.