I suspect vaccines might be a bit of a public relations move for some Big pharm companies. Most of the world sees vaccines as good, so creating and marketing vaccines might cast them in a positive light, get their name further known, and thus generate more money.
The Toronto Dominion bank has an environmental fund - yeah, I bet most of the employees like it, but let's face it: they have such a program because it makes them look good in the eyes of the community.
Vaccines might have some of that going on as well.
Vaccines are admittedly very expensive to produce, that might be a part of why there are only 5 companies who make them. The companies that make vaccines do make money off them, though.