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.
If you want to optimise for targeting a specific virus, then yes, narrowly targeting the most stable functional element of that virus is preferable to targeting other elements of that virus. If you want to optimise for having a broad response to related viruses, then a less narrowly targeted response is preferable.
I was explaining why there's potentially a difference between natural immunity and vaccine-mediated immunity, and why one of these may well be preferable if the goal is to generate maximum immunity to a widespread virus. But that's not the actual goal, and as a result policy decisions may differ. Is the risk associated with vaccinating people who have some degree of natural immunity justified by any improvement in immunity they gain as a result? I don't know! I have opinions on the matter, but I'm not qualified to make that determination.
How is that different from a vaccine?