The vaccine either contains or triggers the production of a specific protein that is (fairly) stable across variants - so there's only one thing for the immune system to key off. The concern around natural immunity is that your immune system may respond to some aspect of the virus that isn't as stable, ie it ends up recognising part of the virus that's present in your current infection but may not be in a later infection.
In reality it seems that the immune system does tend to end up targeting the same protein that's in the vaccine, but may be targeting different portions of it (https://pubmed.ncbi.nlm.nih.gov/34103407/ talks about this). My understanding is that current data suggests the naturally acquired immunity is about as robust as the vaccine acquired one, but this wasn't a given.