The reason why cats are allowed in mosques originates in popular legend and there are quite a few regarding the Prophet Muhammad and his love for domestic cats. This is the classic story of Meuzza, his favourite cat who was asleep on the sleeve of his robe (called a thobe or thawb in Saudi Arabia). Muhammad did not want to disturb Meuzza when called to prayers so he cut the sleeve off the thawb leaving Muezza sleeping peacefully.
When Muhammad returned Meuzza awoke and bowed in thanks. Muhammad stroked his cat companion three times whereupon he was given a permanent place in the Islamic Paradise. Since that moment cats have been left alone and are even permitted inside mosques. You’ll see some videos online of imams (the person who leads prayers in a mosque) welcoming mother cats with her kittens who have been encouraged to come into their mosque to make a safe nest for the family. There are other videos of cats on the carpets among praying Muslims inside mosques. The cats look at home and very contented.
Another popular Prophet legend
In another popular legend concerning the Prophet a cat is said to have saved his life. Apparently a snake crawled into the sleeve of his thawb and refused to leave his comfy resting place.
The cat in question was ‘consulted’ and asked the snake to show its head so that discussions could take place about the snake’s departure. The snake obliged and as soon as its head popped out of the sleeve the cat pounced and carried the snake away.
From that time it was ‘officially decreed that no cat should ever be hit with anything except a ball of cotton’.
Source and quote from Dr Morris’s book Cat World.
P.S. There is sadly a disconnect between the ideal of the Prophet’s relationship with domestic cats (and I hope stray and feral cats) and the relationship today between many Muslims and cats. In countries such as Pakistan where the predominant religion is Islam there are many abused street cats. Also many Muslims simply do not like or respect cats and you’ll find that there are less domestic cats among Muslim households than those of secular households in my opinion. It appears that Muhammad’s influence over modern Muslims has waned in regards to companion animal welfare.