The Messenger of Allah ﷺ said, "When a judge exercises his judgment, striving to reach the correct ruling, and he gets it right, he receives two rewards. When he exercises his judgment and errs, he still receives one reward."
أخبرنا إسحق بن منصور قال حدثنا عبد الرزاق قال أنبأنا معمر عن سفيان عن يحيى بن سعيد عن أبي بكر محمد بن عمرو بن حزم عن أبي سلمة
قال رسول الله ﷺ إذا حكم الحاكم فاجتهد فأصاب فله أجران وإذا اجتهد فأخطأ فله أجر
Bukhari reported it in "Holding Fast to the Book and the Sunnah," chapter on the reward of the judge who exercises ijtihad and gets it right or gets it wrong, hadith 7352, as a suspended report, and Muslim reported it in "Judgments," chapter explaining the reward of the judge who exercises ijtihad and gets it right or gets it wrong, hadith 1716, from the hadith of Abu Bakr bin Amr bin Hazm, with this wording. It is also found in Al-Kubra, hadith 5920.