Hurayth bin Zuhayr said: Abdullah bin Mas'ud (may Allah be pleased with him) said: O people, a time came upon us when we neither judged nor were we present there, and Allah Almighty has brought us to the rank you see. After today, if anyone has to give a judgement, let him do so in accordance with the Book of Allah. If it is not in the Book of Allah, then judge in accordance with the Sunnah of the Messenger (peace and blessings be upon him). If it is not in the Book or the Sunnah, then take into consideration the judgements of the righteous. If it is not in the Book, the Sunnah or the judgements of the righteous, then use your own opinion. Let no one say: I am afraid, or: I think. "The lawful is clear and the unlawful is clear, and between them are doubtful matters. Leave what causes you doubt for what does not."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب آداب القاضي / 20343