The thing you are referring to is called pelting. It was a form of public punishment that was popular during the Middle Ages. People would be placed in a wooden contraption, similar to a stocks, usually on the public square or market. They were then subjected to ridicule, taunting, and humiliation, and other members of the public were encouraged to throw tomatoes or other objects at them.
The practice of pelting was seen as a way to humiliate criminals and draw attention to their wrongdoings. The practice was mostly phased out in the 19th century and today it is generally considered to be a cruel and unusual form of punishment.