Cats often live in temples in Japan- it is a safe place for them as they are often wild rather than being pets. They survive by the foods people bring them and I suppose also by capturing mice and insects or whatever else they can find.
Japanese people will say that theie attitude towards the dignity of animals is different to that in the west- that animals that we consider domesticated are considered just as capable of remaining wild and looking after themselves. In practice though, the only animal this really applies to these days is cats, who are either cherished or despised as vermin, depending on whom you ask. Some people give them food, some people (sadly) give them poisoned food, believing them to be ridden with parasites and diseases (though I have never heard of anyone becoming sick from contact with a cat in Japan).
Generally they survive and on their own, feline terms, lending to the mystical ambiance of the temples, which they seem to 'guard' from unseen dangers which only a cat can smell.