One the most general level, most literature portrays people engaging in social interactions. Thus literature gives an image of society in words just as your bathroom mirror gives a reflected visual image of your face in the morning. Just as you cannot see your own face without a mirror, some argue that we can best observe our society as it is distilled and reflected in literature.
The specific choice of the word "mirror," however, suggests a particular moment in the history of literary criticism, namely The Mirror and the Lamp: Romantic Theory and the Critical Tradition, a work of literary criticism published in 1953 by the American literary critic Meyer Howard Abrams.
In this work, Abrams distinguishes between two types of literary work or attitude, the romantic and the classical. Classical literature attempts to imitate reality and hold a "mirror" up to it. It is distinguished by realism, restraint, and a sense of probability. Romantic literature, on the other hand, is visionary and seeks to provide its own light (like a lamp) and have that light transform our perceptions or create something new.
Thus when you ask how literature is a mirror to society, it's important to consider that some types of literature are intended as mirrors, reflecting on society as it is, and other types act as visionary or prophetic "lamps."