Usually, natural immunity after infection is stronger than immunity from vaccination. Very often, for good immunity, you need to be vaccinated, and then also do revaccination. That is, the effect will not be the first time.
So why don't we get immunity naturally?
Because you can die from certain diseases, and the price of such immunity will be too high.
It would be foolish to try to get pneumococcal disease to get immunity to pneumococcus.
Having recovered from, for example, rubella during pregnancy, they easily lose the child.
Hepatitis B virus is very easy to get infected and then it is just as easy to get liver cancer from it.
I love the measles example. Measles vaccine causes severe allergic reactions in about one in a million. Moreover, if you do not get vaccinated and get sick with measles it is good with symptoms, then the probability of dying approaches one case in 500. Do you feel the difference?
When is the vaccine better
This also happens. The human papillomavirus vaccine causes the immune system to churn out much more antibodies than the infection itself.
In young children, immunity against Haemophilus influenzae and pneumococcus is poorly developed. The child's body cannot properly digest the shell of these microbes, therefore, after an infection, vaccination is still needed.
A similar story happens with the tetanus vaccine. Even microscopic amounts of tetanus toxin can cause disease, but this is not enough for lifelong immunity.
Plus, vaccines contain adjuvants that are abused by everyone. These are special additives that slip the vaccine into the immune system in the most beneficial form and for a long time. This gives our body a clear target for the immune response and time to build up antibodies.
Don't try to dodge and cheat with vaccines. Without them, you are at great risk.