It was narrated that 'Amr bin Al-'As said "The Messenger of Allah said: 'If a judge passes a judgment having exerted himself to arrive at what is correct, and he is indeed correct, he will have two rewards. If he passes judgment having exerted himself to arrive at what is correct, but it is incorrect, he will have one reward'." I narrated it to Abu Bakr bin Hazm and he said: "This is what Abu Salamah narrated to me from Abu Hurairah.
The Prophet Muhammad ﷺ also taught us that justice should be done regardless of whether it benefits us or harms us personally; this hadith reinforces this teaching by reminding us that we will still receive reward from Allah even if our judgement turns out to be wrong in the end.