By injecting dead cells of the disease into the body, the body can analysis what it is supposed to be fighting off before it gets the active diseases. So if the body does actually get the disease then it knows how to fight it off and can have a better chance at doing it.