All analogies break down fairly quickly, so I'll preface this with a clear vote of support for what you said. But in this case the purpose of a hospital is to provide for the sick. The purpose of a city is to do the opposite of homelessness - a city is a massive collection of homes.
The existence of a large homeless population is concerning for reasons you allude to, but because a more appropriate analogy might be "the piles of corpses made the hospital uninviting". The point of a city is to not have homeless people and so something fundamental went wrong if there is a big homeless population.