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: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.
القرآن:٥:٤٠

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

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

See similar narrations below:

Collected by Qurʾān
quran:2:107

Do you not know that to Allah belongs the dominion of the heavens and the earth and ˹that˺ you have not besides Allah any protector or any helper?  

Do you not know that to God belongs the kingdom of the heavens and the earth, doing what He pleases, and that you have none, besides God, other than God, neither protector, to safeguard you, nor helper?, to keep away His chastisement when it comes.
القرآن:٢:١٠٧

أَلَمْ تَعْلَمْ أَنَّ اللَّهَ لَهُ مُلْكُ السَّمَاوَاتِ وَالْأَرْضِ ۗ وَمَا لَكُمْ مِنْ دُونِ اللَّهِ مِنْ وَلِيٍّ وَلَا نَصِيرٍ  

{ألم تعلم أن الله له ملك السموات والأرض} يفعل ما يشاء {وما لكم من دون الله} أي غيره {من} زائدة {وليٌ} يحفظكم {ولا نصير} يمنع عنكم عذابه إن أتاكم، ونزل لما سأله أهل مكة أن يوسعها ويجعل الصفا ذهباً.
quran:3:189

And to Allah belongs the dominion of the heavens and the earth, and Allah is over all things competent.  

To God belongs the kingdom of the heavens and of the earth, the storehouses of rain, sustenance, vegetation and so forth, and God has power over all things, including the punishing of disbelievers and the saving of believers.
القرآن:٣:١٨٩

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

{ولله ملك السماوات والأرض} خزائن المطر والرزق والنبات وغيرها {والله على كل شيء قدير} ومنه تعذيب الكافرين وإنجاء المؤمنين.
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.
القرآن:٤٨:١٤

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

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