Why don't we form immunity to some infections?
The answer is sort of hidden behind the very first paragraph of your linked question:


  Vaccines work by introducing an attenuated strain of the pathogen (or alternatively the antigens that are normally present on the pathogens surface) into the body, whereupon the body mounts an immune response.


The body mounts an immune response based upon a particular epitope (molecule/protein chain) derived from the infection itself.

If the bacteria/virus/parasite evolves so that the molecules/proteins on its surface change significantly, then the version stored in Memory Cells will no longer apply. There's some wiggle room depending on epitope length and specificity of the Immune Response (highly specific MHC proteins will invoke a very strong, very efficient response - while less specific [usually B-cell or early T-cell responses] will invoke a weaker, less effective response), but because pathogens can mutate so quickly it's not uncommon that you'll encounter a descendant of a virus you already encountered that has dramatically different characteristics.

Some pathogens are also just very "clever" at avoiding the immune system. Sometimes they can produce shells which can't be broken down to derive epitopes from, sometimes they live within host cells and simply hide (the most well known example being HIV), other times they can present the same "I'm part of the body!" MHC proteins that tells the immune system not to attack them, and they can even hide in parts of the body where the immune system rarely visits (eyes, brain, other very specialized tissues).

And at times the pathogen can be both very adaptive and very "clever", as in the case for Staphylococcus aureas - which can inactivate antibodies through surface proteins and has the ability to adapt to new antibodies very quickly.

You can think of it like a game of chess. If you play against the same person all the time you're going to learn their moves, their strategy, and be able to beat them very quickly. If you switch partners, or your regular partner learns new moves, you'll spend some time adapting to the new play style you've encountered before being able to win consistently again. Bacteria and virii are simply very, very good at coming up with new play styles.