Why do we develop lifelong immunity to some diseases, but not others?

Why do some diseases infect us again and again?

Source: https://www.livescience.com/why-lifelong-immunity.html