Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:21:78

And ˹mention˺ David and Solomon, when they judged concerning the field - when the sheep of a people overran it ˹at night˺, and We were witness to their judgement.  

And, mention, David and Solomon, that is, ˹mention˺ their story (Dāwūda wa-Sulaymāna is substituted by ˹the following, idh yahkumāni …˺) when they gave judgement concerning the tillage, a field of crops or a vineyard, when the sheep of a ˹certain˺ people strayed into it, that is, ˹when these sheep˺ grazed there at night, but without a shepherd, because they had escaped; and We were witnesses to their judgement (lihukmihim shāhidīna: here the plural person is being used in the case of a dual). David decreed: to the owner of the tillage belong the head of the sheep. Solomon decreed: he shall benefit from ˹the use of˺ their milk, offspring and wool until such time as the tillage is restored to its original state at the hands of the owner ˹of the sheep˺, after which he ˹the owner of the tillage˺ should return them ˹the sheep˺ to him ˹their owner˺.
القرآن:٢١:٧٨

وَدَاوُودَ وَسُلَيْمَانَ إِذْ يَحْكُمَانِ فِي الْحَرْثِ إِذْ نَفَشَتْ فِيهِ غَنَمُ الْقَوْمِ وَكُنَّا لِحُكْمِهِمْ شَاهِدِينَ  

{و} اذكر {داود وسليمان} أي قصتهما ويبدل منهما {إذ يحكمان في الحرث} هو زرع أو كرم {إذ نفشت فيه غنم القوم} أي رعته ليلاً بلا راع بأن انفلتت {وكنا لحكمهم شاهدين} فيه استعمال ضمير الجمع لاثنين، قال داود لصاحب الحرث رقاب الغنم، وقال سليمان: ينتفع بدرها ونسلها وصوفها إلى أن يعود الحرث كما كان بإصلاح صاحبها فيردها إليه.