Naturally-occurring herd immunity is a temporary effect. Only artifically-imposed herd immunity (i.e. vaccination) is lasting.
If an epidemic sweeps through and infects most of the "herd", that herd has herd immunity.
In time as individuals born and others die, the fraction of the herd that is immune goes down and the herd is vulnerable to the same epidemic.
But with vaccination, herd immunity can be sustained indefinitely. With no further epidemics. But, as measles has shown, only as long as a high enough fraction of the herd vaccinates.
Of course it is also possible that if enough of the herd is immune for long enough that the epidemic goes extinct. This takes a lot of work but is how we got rid of Smallpox
Effective contact tracing and social distancing can achieve the same end, which is how we got rid of SARS.