I think the virus/bacteria decides when the pandemic is over via mutation or failing to reproduce aggressively. Public health and medical efforts help hasten these occurrences, but it’s really up to how the dice roll. Evolutionary pressure has to favour going endemic for it to happen.