how vaccination works
A vaccination is a treatment which makes the body stronger against a particular infection.
The body fights infections using the immune system, which is made up of millions upon millions of cells including T cells and B cells. An important feature of the immune system is that it is much stronger when fighting a disease which it has already fought against before. Vaccination involves showing the immune system something which looks very similar to a particular virus or bacteria, which helps the immune system be stronger when it is fighting against the real infection.
As far as cowpox vaccination is concerned, it might have happened that this vaccination could not have killed all the bacterias as result people would have suffered from little cowpox.