Literature is a mirror of society because it gives an image, but the image is not necessarily a true image. The image can be distorted in reality or perceived as distorted by society as a whole.
Literature tends to focus on subjects current to societal engagement. This type of reflection is observed in many different time periods. Two dramatic pieces focusing on African-American history and struggle, "A Raisin in the Sun" (1959) and Roots (1976) were written during a period of great civil strife in American society. Similarly, other famous authors of recent note such as Tom Clancy are successful because their books deal with intrigue, national security and terrorism which are all on the forefront of the American mindset.
Literature can also be distorted by the perception of society looking into the mirror. For example, political commentary has always been a huge part of literature whether covert comments on life through drama or overt attacks on the political mechanism. These commentaries are often partisan in their attacks and represent a distorted view of society in the mirror, focusing on what the author perceives as a scar.
The mirror literature provides will continue to expose society to views not seen from our place within. We may see scars of political rhetoric, exposed to struggles, or only focus on the beauty of poetry highlighting the best of society.
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."