Why are there cats everywhere?

The short answer

They're the city's pest control.

Cats have been part of medina life for centuries. They keep the rat and mouse population down in a city built on narrow streets and open drains. They're tolerated, fed scraps by shopkeepers and residents, and largely left to roam. Most are semi-feral — friendly enough to approach but not domesticated. Some have eye infections or are underfed. A handful of cat food and a few dirhams' worth of eye drops from any pharmacy will be much appreciated.