Allah, glorified be His praise, says: "And (remember) Dawud and Sulayman (peace be upon them both), when they were judging concerning the field, when the people's sheep had grazed in it by night, and We were witness to their judgement." [Surah al-Anbiya: 78] "So We made Sulayman understand it, and to each We gave judgement and knowledge." [Surah al-Anbiya: 79]
Hadith Referenceالسنن الكبرى للبيهقي / كتاب آداب القاضي / Q20365