It is narrated from Haram bin Sa'd bin Muhisah that the she-camel of Bara' bin Azib (may Allah be pleased with him) entered the garden of a people and destroyed it. So the Messenger of Allah (ﷺ) gave the verdict that during the day, the protection of property is the responsibility of the owners, and if livestock cause damage at night, then their owner is liable for it. (That is, the loss occurring at night will be taken from the owner of the animal.)
Hadith Referenceمسند الإمام الشافعي / كتاب القضاء والأحكام والدعاوى والبينات واليمين ومع الشاهد والأيمان والشهادات / 1691
Hadith Takhrijحديث صحيح وانظر الحديث الآتي: اخرجه ابن ماجة ، الأحكام، باب الحكم فيما افسدت المواشي (2332)۔ وابو داود، البيوع، باب المواشي تفسد زرع قوم (3569)۔