Question: If a man finds a sheep in a village whose people have fled out of fear of war, and he thinks that its owners have turned it loose, renounced it, and left it, and that if he does not take it, it will die – is it permissible for him to take it for himself?
Answer: If the matter is as described, and the man finds a sheep or more, then he takes it either for himself or on behalf of its owner. If he slaughters the sheep, he must ascertain its descriptive signs and distinguishing marks, and then slaughter it.
After that, he must ask the people of that locality about the owner of the sheep. If he finds (the owner) and it becomes clear to him that he is the owner, he gives him the sheep or its value. If he does not find an owner for it, he gives the sheep or its value in charity. If the one who found the sheep is poor, then let him spend it upon himself.
Source: Min Thimār al-ʿIlm wa al-Ḥikmah vol.2