Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:4:58

Indeed, Allah commands you to render trusts to whom they are due and when you judge between people to judge with justice. Excellent is that which Allah instructs you. Indeed, Allah is ever Hearing and Seeing.  

Verily, God commands you to restore trusts, that is, the rights entrusted ˹to you by others˺, back to their owners: this was revealed when ‘Alī, may God be pleased with him, took the key of the Ka‘ba from its keeper, ‘Uthmān b. Talha al-Hajabī, by force, upon the arrival of the Prophet (s) in Mecca in the year of the Conquest, after he ˹‘Uthmān˺ had tried to prevent him ˹‘Alī from taking it˺ saying, ‘If I had known that he was the Messenger of God, I would not have prevented him’. The Messenger of God (s) then ordered him ˹‘Alī˺ to give it back to him ˹‘Uthmān˺ saying to him, ‘Here you are, ˹it is yours˺ now and always’. He ˹‘Uthmān˺ was amazed by this, whereupon ‘Alī recited to him this verse, and he accepted Islam. Upon his death, he ˹‘Uthmān˺ gave it ˹the key˺ to his brother, Shayba, and thus it remained in ˹the keep of˺ his descendants. Although the verse was revealed regarding a specific occasion, it holds true in general on account of the plural person ˹to which it is addressed˺. And when you judge between people, He commands, that you judge with justice. Excellent is (ni‘immā, the mīm of ni‘ima has been assimilated with the indefinite particle mā, which is the object described, in other words, na‘ima shay’an, ‘an excellent thing ˹is˺’) the admonition God gives you, to restore a trust and to judge with justice. God is ever Hearer, of what is said, Seer, of what is done.
القرآن:٤:٥٨

إِنَّ اللَّهَ يَأْمُرُكُمْ أَنْ تُؤَدُّوا الْأَمَانَاتِ إِلَىٰ أَهْلِهَا وَإِذَا حَكَمْتُمْ بَيْنَ النَّاسِ أَنْ تَحْكُمُوا بِالْعَدْلِ ۚ إِنَّ اللَّهَ نِعِمَّا يَعِظُكُمْ بِهِ ۗ إِنَّ اللَّهَ كَانَ سَمِيعًا بَصِيرًا  

{إن الله يأمركم أن تؤدوا الأمانات} أي ما اؤتمن عليه من الحقوق {إلى أهلها} نزلت لما أخذ عليّ ؓ مفتاح الكعبة من عثمان بن طلحة الحجبي سادنها قسرا لما قدم النبي ﷺ مكة عام الفتح ومنعه وقال لو علمت أنه رسول الله لم أمنعه فأمر رسول الله ﷺ برده إليه وقال هاك خالدة تالدة فعجب من ذلك فقرأ له عليُّ الآية، فأسلم وأعطاه عند موته لأخيه شيبة فبقي في ولده والآيةُ وإن وردت على سبب خاص فعمومها معتبر بقرينة الجمع {وإذا حكمتم بين الناس} يأمركم {أن تحكموا بالعدل إن الله نعمَّا} فيه إدغام ميم نعم في ما النكرة الموصولة أي نعم شيئا {يعظكم به} تأدية الأمانة والحكم بالعدل {إن الله كان سميعا} لما يقال {بصيرا} بما يفعل.

See similar narrations below:

Collected by Ḥākim
hakim:2925Abū Muḥammad ʿAbdullāh b. Muḥammad b. Isḥāq al-Khuzāʿī Bimakkah > Abū Yaḥyá b. Abū Masarrah > ʿAbdullāh b. Yazīd al-Muqriʾ > Ḥarmalah b. ʿImrān > Abū Yūnus > Abū Hurayrah Yaqraʾ Hadhih al-Āyah In Allāh Yaʾmurukum > Tuʾaddūā al-Amānāt > Ahlihā And ʾIdhā Ḥakamtum Bayn al-Nās

[Machine] I heard Abu Huraira reciting this verse: "Indeed, Allah commands you to render trusts to whom they are due and when you judge between people to judge with justice. Excellent is that which Allah instructs you. Indeed, Allah is ever Hearing and Seeing." [Surah An-Nisa 4:58]  

الحاكم:٢٩٢٥أَخْبَرَنَا أَبُو مُحَمَّدٍ عَبْدُ اللَّهِ بْنُ مُحَمَّدِ بْنِ إِسْحَاقَ الْخُزَاعِيُّ بِمَكَّةَ ثنا أَبُو يَحْيَى بْنُ أَبِي مَسَرَّةَ ثنا عَبْدُ اللَّهِ بْنُ يَزِيدَ الْمُقْرِئُ ثنا حَرْمَلَةُ بْنُ عِمْرَانَ حَدَّثَنِي أَبُو يُونُسَ

سَمِعْتُ أَبَا هُرَيْرَةَ يَقْرَأُ هَذِهِ الْآيَةَ {إِنَّ اللَّهَ يَأْمُرُكُمْ أَنْ تُؤَدُّوا الْأَمَانَاتِ إِلَى أَهْلِهَا وَإِذَا حَكَمْتُمْ بَيْنَ النَّاسِ أَنْ تَحْكُمُوا بِالْعَدْلِ إِنَّ اللَّهَ نِعِمَّا يَعِظُكُمْ بِهِ إِنَّ اللَّهَ كَانَ سَمِيعًا بَصِيرًا} [النساء 58]  

«هَذَا حَدِيثٌ صَحِيحٌ عَلَى شَرْطِ الشَّيْخَيْنِ وَلَمْ يُخَرِّجَاهُ» على شرط البخاري ومسلم