The reason the second infection is so bad is exactly as outlined above: your immune system 'recognises' the second variant and produces antibodies that it learnt when fighting off the first variant you recovered from. Unfortunately, these antibodies are useless against the second variant, and you have a bad time.
This exact same issue happens with the current vaccine for dengue, which is why it is only given to people who have already had dengue of some kind, or in populations where most people have had it before. For a situation where this did not happen see the section titled 'Phillipines controversy' in the wikipedia article.
There is currently a lot of work being done to produce vaccines that protect against all 4 variants at the same time, with some promise for the years ahead as trial results come in!
Maybe the explanations are simplified but I don't quite understand how the immune system could fail to recognise permutations of proteins or any other differentiating factor between COVID-19, its variants and mRNA vaccines; nor what makes this specific example of vaccination riskier.