As per Wikipedia:

The pillory was a device made of a wooden or metal framework erected on a post, with holes for securing the head and hands, formerly used for punishment by public humiliation and often further physical abuse. The pillory is related to the stocks.

Rather like the lesser punishment called the stocks, the pillory consisted of hinged wooden boards forming holes through which the head and/or various limbs were inserted; then the boards were locked together to secure the captive. Pillories were set up to hold petty criminals in marketplaces, crossroads, and other public places. They were often placed on platforms to increase public visibility of the offender. Often a placard detailing the crime was placed nearby; these punishments generally lasted only a few hours.

In being forced to bend forward and stick their head and hands out in front of them, offenders in the pillory would have been extremely uncomfortable during their punishment. However, the main purpose in putting criminals in the pillory was to publicly humiliate them. On discovering that the pillory was occupied, people would excitedly gather in the marketplace to taunt, tease and laugh at the offender on display.

Those who gathered to watch the punishment typically wanted to make the offender's experience as unpleasant as possible. In addition to being jeered and mocked, those in the pillory might be pelted with rotten food, mud, offal, dead animals, and animal excrement. As a result, criminals were often very dirty by the end of their punishment, their faces and hair begrimed with the smelly refuse with which they had been pelted. Sometimes people were killed or maimed in the pillory because crowds could get too violent and pelt the offender with stones, bricks and other dangerous objects. However, when Daniel Defoe was sentenced to the pillory in 1703 for Seditious libel, he was regarded as a hero by the crowd and was pelted with flowers.

The criminal could also be sentenced to further punishments while in the pillory: humiliation by shaving off some or all hair or regular corporal punishment(s), notably flagellation (the pillory serving as the "whipping post") or even permanent mutilation such as branding or having an ear cut off (cropping), as in the case of John Bastwick.