The Torah tells us that if a person permits his animals to graze in another person’s field or vineyard – even if he just let it loose and didn’t bring it there – then he must repay what they eat (or trample) with the best of his own crop. This section is the basis of the laws of shein and regel – literally “tooth” and “foot,” referring to damage caused by animals by eating or trampling.
The reason for this mitzvah is obvious: people have to take charge of their animals and not permit them to run around unchecked, damaging others’ property. Genesis 24:32 tells us that Eliezer, the servant of Abraham, unmuzzled his camels to feed them. Rashi there cites the Midrash that Abraham’s camels were muzzled specifically so that they shouldn’t graze on other people’s land. Maaseh avos siman l’banim (the deeds of the fathers serve as a sign to the children), it behooves us to do likewise and carefully watch the animals for which we are responsible.
This mitzvah is incumbent upon the courts. In the Talmud, this mitzvah is the very first topic in the tractate of Baba Kama. In the Shulchan Aruch, it is found in Choshen Mishpat 390. It is #240 of the 248 positive mitzvos in the Rambam’s Sefer HaMitzvos.