The Prophet ﷺ said, "Judges are of three kinds, one in Paradise and two in the Fire. As for the one in Paradise, he is a man who recognized the truth and judged by it. A man who recognized the truth but acted unjustly in his ruling is in the Fire, and a man who judged between people in ignorance is in the Fire."
حدثنا محمد بن حسان السمتي حدثنا خلف بن خليفة عن أبي هاشم
عن النبي ﷺ قال القضاة ثلاثة واحد في الجنة واثنان في النار فأما الذي في الجنة فرجل عرف الحق فقضى به ورجل عرف الحق فجار في الحكم فهو في النار ورجل قضى للناس على جهل فهو في النار
[Its chain of transmission is daif] Ibn Majah narrated it in the Book of Rulings, chapter "The Judge Who Exercises Ijtihad and Reaches the Truth," Hadith 2315, from the hadith of Khalaf bin Khalifa, with this wording. Tirmidhi also narrated it, Hadith 1322(M). This hadith has many routes, all of them daif.* Khalaf bin Khalifa's memory became confused later in life.