Al-Sha'bi (may Allah have mercy on him) said: When Umar bin al-Khattab (may Allah be pleased with him) appointed Shurayh (may Allah have mercy on him) as judge of Kufa, he advised him: Whatever issue is clear to you from the Book of Allah, do not seek anyone's counsel about it; whatever is not clear from the Book of Allah, follow the Sunnah in it; and whatever is not clear in the Sunnah, exercise your own judgement (ijtihad) in it.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب آداب القاضي / 20312
Al-Sha'bi (may Allah have mercy on him) said that Sayyiduna Umar (may Allah be pleased with him) wrote to Qadi Shurayh (may Allah have mercy on him): When a matter is in the Book of Allah, judge according to it, and do not let people turn you away from it. If it is not in the Book of Allah, judge in accordance with the Sunnah of the Messenger of Allah (peace and blessings be upon him). If it is neither in the Book of Allah nor in the Sunnah of the Messenger of Allah (peace and blessings be upon him), then judge as the rightly guided imams judged. If there is nothing in the Book of Allah, the Sunnah of the Messenger of Allah (peace and blessings be upon him), or the judgements of the imams, then you have the choice: if you wish, exercise your own judgement, or else consult me; yet I consider your consulting me to be the better course.
The Shaykh said: Sayyiduna Umar (may Allah be pleased with him) indicated the occasions for consultation: principles that he (Shurayh) might not have reached; if he asked, he would be informed of them.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب آداب القاضي / 20313