Umar bin Khattab reported,

He wrote back to him, "Judge by what is in the Book of Allah. If it is not in the Book of Allah, then by the Sunnah of the Messenger of Allah ﷺ. If it is not in the Book of Allah nor in the Sunnah of the Messenger of Allah ﷺ, then judge by what the righteous have judged. If it is not in the Book of Allah, nor in the Sunnah of the Messenger of Allah ﷺ, and the righteous have not judged on it, then if you wish, go ahead, and if you wish, hold back, and I see nothing but good for you in holding back. Peace be upon you."

Nasai 5401

Sahih

أخبرنا محمد بن بشار قال حدثنا أبو عامر قال حدثنا سفيان عن الشيباني عن الشعبي عن شريح أنه كتب إلى

عمر يسأله

فكتب إليه أن اقض بما في كتاب الله فإن لم يكن في كتاب الله فبسنة رسول الله ﷺ فإن لم يكن في كتاب الله ولا في سنة رسول الله ﷺ فاقض بما قضى به الصالحون فإن لم يكن في كتاب الله ولا في سنة رسول الله ﷺ ولم يقض به الصالحون فإن شئت فتقدم وإن شئت فتأخر ولا أرى التأخر إلا خيرا لك والسلام عليكم

النسائي 5401صحيح
Contents
Reference
Commentary
Ayat
Collection
Sunan Nasai Sughra
Book
Etiquette of judges
Chapter
Ruling by the consensus of the people of knowledge
Numbering
Darussalam 5401
Nasai 5401