There are multiple components to the immune system. Some cells and processes mount a non-specific response to anything unrecognized. There are distinct cells and processes dedicated to learning, memory, and engaging a targeted re-response against recognized threats. They're certainly related, but they are subject to independent modification. One of the main functions of the non-specific system is to collect the unknown invaders and present them to the memory system for analyzing and targeting.
The immune system easily exterminates 99.99+% of all bacteria/viruses, the ones we make vaccines for are the ones that use some trick to disrupt the normal immune response. In many or most cases this involves a pathogen producing some toxin or signalling molecule that specifically mimics or targets critical components of the immune system itself. This is significant for a pair of reasons. One, it's generally only effective if the pathogen has a chance to build up a small colony and has a chance to build up a significant level of the disruptive chemical agent. The immune-memory response can rapidly pump out an overwhelming highly targeted response before the invader has a chance to disrupt the non-targeted immune response. The other significant point is that if a pathogen is specifically mimicking or targeting critical components of the immune system.... then evolving to escape that threat requires modifying exactly those targeted critical systems. Modifying critical components of the immune system to escape the targeting of one specific pathogen typically results in diminished immune function against generic threats. And this specific pathogen is just going to co-evolve to re-target whatever change we made thing to escape it. This puts us right back where we started, vulnerable to this pathogen, except with diminished general immune function from our attempt to break the target lock that the pathogen has on us.
If the immune system can rely on vaccines to take over the job of "showing" those handful of immune-disrupting pathogens to the immune-memory-system, and if the immune system can rely upon an overwhelming targeted memory response to those few immune-disrupting pathogens, then that frees up the primary non-specific immune response to optimize itself to best take down generic invaders.