The immunity induced by the vaccines is said to be potentially more effective and/or longer-lasting than the immunity obtained from a prior infection.
There is also an open question about whether people who are sufficiently immune from prior infection that they won't get serious symptoms are still able to pass the virus to others during a "fighting it off again successfully" phase.
Immunity is not a simple yes-no boolean. It's not even a single variable, because there are different parts of the immune system memory.