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:48:14

And to Allah belongs the dominion of the heavens and the earth. He forgives whom He wills and punishes whom He wills. And ever is Allah Forgiving and Merciful.  

And to God belongs the kingdom of the heavens and the earth: He forgives whomever He will and chastises whomever He will; and God is ever Forgiving, Merciful, that is to say, He is ever possessed of the attributes mentioned.
القرآن:٤٨:١٤

وَلِلَّهِ مُلْكُ السَّمَاوَاتِ وَالْأَرْضِ ۚ يَغْفِرُ لِمَنْ يَشَاءُ وَيُعَذِّبُ مَنْ يَشَاءُ ۚ وَكَانَ اللَّهُ غَفُورًا رَحِيمًا  

{ولله ملك السماوات والأرض يغفر لمن يشاء ويعذِّب من يشاء وكان الله غفورا رحيما} أي لم يزل متصفا بما ذكر.

See similar narrations below:

Collected by Qurʾān
quran:5:40

Do you not know that to Allah belongs the dominion of the heavens and the earth? He punishes whom He wills and forgives whom He wills, and Allah is over all things competent.  

Do you not know (the interrogative here is meant as an affirmative) that to God belongs the kingdom of the heavens and the earth? He chastises, him for, whom He wills, chastisement for, and forgives, him for, whom He wills, forgiveness, and God has power over all things, including chastising and forgiving.
القرآن:٥:٤٠

أَلَمْ تَعْلَمْ أَنَّ اللَّهَ لَهُ مُلْكُ السَّمَاوَاتِ وَالْأَرْضِ يُعَذِّبُ مَنْ يَشَاءُ وَيَغْفِرُ لِمَنْ يَشَاءُ ۗ وَاللَّهُ عَلَىٰ كُلِّ شَيْءٍ قَدِيرٌ  

{ألم تعلم} الإستفهام فيه للتقرير {أن الله له ملك السماوات والأرض يعذَّب من يشاء} تعذيبه {ويغفر لمن يشاء} المغفرة له {والله على كل شيء قدير} ومنه التعذيب والمغفرة.
quran:3:129

And to Allah belongs whatever is in the heavens and whatever is on the earth. He forgives whom He wills and punishes whom He wills. And Allah is Forgiving and Merciful.  

To God belongs all that is in the heavens and the earth, as possessions, creatures and servants; He forgives whom He wills, forgiveness for, and chastises whom He wills, chastisement for. And God is Forgiving, of His friends, Merciful, to those who obey Him.
القرآن:٣:١٢٩

وَلِلَّهِ مَا فِي السَّمَاوَاتِ وَمَا فِي الْأَرْضِ ۚ يَغْفِرُ لِمَنْ يَشَاءُ وَيُعَذِّبُ مَنْ يَشَاءُ ۚ وَاللَّهُ غَفُورٌ رَحِيمٌ  

{ولله ما في السماوات وما في الأرض} ملكا وخلقا وعبيدا {يغفر لمن يشاء} المغفرة له {ويعذب من يشاء} تعذيبه {والله غفور} لأوليائه {رحيم} بأهل طاعته.