ذَٰلِكَ بِمَا قَدَّمَتْ أَيْدِيكُمْ وَأَنَّ ٱللَّهَ لَيْسَ بِظَلَّٰمٍۢ لِّلْعَبِيدِ
That is for what your hands have put forth [of evil] and because Allah is not ever unjust to His servants."
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.