Why do libraries have that smell?

The musty smell is most likely cellulose decay. Since the mid-19th century, when papermakers began using groundwood pulp in place of cotton or linen, most paper has contained an unstable compound called lignin, which breaks down into acids and makes paper very brittle. Since 2001, the Library of Congress has treated at least 250,000 books every year with magnesium oxide. The chemical deacidifies paper and slows decay.