Praise be to Allah.
One aspect of the bounty of Allaah towards this ummah is that He has created means of expiation before people are brought to account. Shaykh al-Islam Ibn Taymiyah (may Allaah have mercy on him) mentioned ten things which will bring about expiation, one of which is the torment in the grave.
He (may Allaah have mercy on him) said:
“Whatever befalls the believer in this world, in al-barzakh (the period between death and resurrection) and during the Day of Resurrection of pain which is a torment, Allaah will cause that to expiate for his sins. It was reported in al-Saheehayn that the Prophet (peace and blessings of Allaah be upon him) said: ‘Nothing befalls the believer of disease, affliction, grief or harm, even a thorn which pricks him, but Allaah will cause it to expiate for his sins.’”(Majmoo’ al-Fataawaa, 24/375).
And he (may Allaah have mercy on him) said:
“The eighth reason: whatever happens to him in the grave of trials, being squeezed, and terror. These are some of the things which will expiate for his sins.”(Majmoo’ al-Fataawaa, 7/500).
Shaykh al-Islam Ibn Taymiyah also said, in Minhaaj al-Sunnah (6/238), that among the things which expiate for bad deeds is: what the believer is tested with in his grave of being squeezed, and the interrogation of the two angels.
And Allaah knows best.