1. They didn't know what caused it for a long time, so even after the cause was discovered, there were a lot of active cases from before.
2. Crowded living conditions. If you've seen the way immigrants in the major cities lived in the early 20th century, you'll understand why it spread and why one of the early hypotheses was that TB was hereditary. (If the family lived in one room, they would all get it eventually.)
Epidemic TB was just dying out when I was a kid. We received immunizations and the like through the school system, and one thing we were required to take every couple of years was a tuberculin test, which tests you for antibodies to TB.
My mother was a kindergarten teacher in a small town, and one little girl who was one of 13 children living in a regular sized house (i.e. really crowded) was diagnosed with active TB. It just so happened that she was diagnosed the day after I had visited my mother's classroom (our respective school systems had different days off) and had played with the students. We and everyone in the class had to have tuberculin tests. Fortunately, mine and my mother's came back negative, and so did the tests given all the other students.