Baseball was the most popular sport for most of the 20th century by being the one best suited to newspaper, radio, and regional broadcasts. Those things have been dying for the past couple decades. They keep making money by playing so many games during months with little competition.
The drug issue didn't do much at all to change baseball's popularity. What it did, was show how weird and irrational the fans are. Those are the people who held on to "tradition" even if it meant ending up with just a small fraction of the NFL's popularity. But they're also the people who are able to support 30 teams with an average value of over $1 billion.