Surah Al-Anfal — Ayah 51 (8:51)
ذَٰلِكَ بِمَا قَدَّمَتۡ أَيۡدِيكُمۡ وَأَنَّ ٱللَّهَ لَيۡسَ بِظَلَّٰمٖ لِّلۡعَبِيدِ ٥١
English translation (Saheeh International)
That is for what your hands have put forth [of evil] and because Allāh is not ever unjust to [His] servants."
Brief commentary
The cause of that painful punishment at the time when your souls are taken out and the burning punishment in your graves and in the Afterlife is because of the evil actions you performed in the world. Allah does not wrong people, but passes judgement on them with fairness. He is not unjust to His slaves.