By rights, the Doctor shouldn't know anything about anything outside of medicine...
And initially he didn't. But he had seven years to expand his horizons. The difference between him and other Mark I EMHs is that he was active continuously instead of rarely, and thus was able to develop his mind far beyond the basic level of the others. By analogy, if an EMH were only activated on, say, an average of four emergency situations a year and left on for an average of six hours per emergency, then at the end of seven years of service that EMH would only be the equivalent of seven days old. Well, keeping in mind that humans sleep for about 1/3 of our lives, make it the equivalent of ten and a half days old. So most EMHs would still be effectively "infants," never having enough time to develop beyond their basic programming, even if they were in service for years. The Doctor was active every day and thus did have the opportunity to grow and learn.