There came upon us a time when we were not judging cases and were not in that position. Then Allah decreed for us that we reached what you now see. So whoever among you is faced with a case to judge after today, let him judge by what is in the Book of Allah. If a matter comes that is not in the Book of Allah, let him judge by what His Prophet ﷺ judged. If a matter comes that is not in the Book of Allah and His Prophet ﷺ did not judge concerning it, let him judge by what the righteous have judged. If a matter comes that is not in the Book of Allah, nor did His Prophet ﷺ judge concerning it, nor did the righteous judge concerning it, then let him exercise his own reasoning, and let him not say, "I am afraid, I am afraid." For the lawful is clear and the unlawful is clear, and between them are doubtful matters. So leave what causes you doubt for what does not cause you doubt.Abu Abdul-Rahman said, "This hadith is excellent, excellent."
أخبرنا محمد بن العلاء قال حدثنا أبو معاوية عن الأعمش عن عمارة هو ابن عمير عن عبد الرحمن بن يزيد قال أكثروا على عبد الله ذات يوم
إنه قد أتى علينا زمان ولسنا نقضي ولسنا هنالك ثم إن الله عز وجل قدر علينا أن بلغنا ما ترون فمن عرض له منكم قضاء بعد اليوم فليقض بما في كتاب الله فإن جاء أمر ليس في كتاب الله فليقض بما قضى به نبيه ﷺ فإن جاء أمر ليس في كتاب الله ولا قضى به نبيه ﷺ فليقض بما قضى به الصالحون فإن جاء أمر ليس في كتاب الله ولا قضى به نبيه ﷺ ولا قضى به الصالحون فليجتهد رأيه ولا يقول إني أخاف وإني أخاف فإن الحلال بين والحرام بين وبين ذلك أمور مشتبهات فدع ما يريبك إلى ما لا يريبك قال أبو عبد الرحمن هذا الحديث جيد جيد
[hasan] Darimi reported it, 1/61, no. 172, and Bayhaqi, 10/115, from the hadith of Amash, through this chain, and it is in Kubra, no. 5945. The hadith has corroborating narrations in Tabarani, 9/210, no. 8921, and elsewhere.