Praise be to Allah.
There are many reasons for which people may be punished in their graves, which Ibn al-Qayyim (may Allaah have mercy on him) listed and said:
Some people may wonder about the reasons for which people may be punished in their graves. This may be answered in two ways: in general and in detail.
In general terms, they may be punished for their ignorance of Allaah, their ignoring His commands and their disobedience towards Him. Allaah does not punish any soul that acknowledged Him, loved Him, obeyed His commands and heeded His prohibitions, nor does He punish the body that was inhabited by that soul.
Punishment in the grave and in the Hereafter are due to the wrath and anger of Allaah towards His slave. Whoever angers Allaah in this world and does not repent, and dies like that, will be punished in al-Barzakh to a level commensurate with Allaah's anger with him.
As for the detailed answer:
The Prophet (peace and blessings of Allaah be upon him) told us about two men whom he saw being punished in their graves. One of them used to walk around spreading malicious gossip among people, and the other failed to take precautions to avoid getting urine on himself. So the latter failed to purify himself as required, and the former did something that creates enmity among people by talking, even if what he says is true.
Thus it may be noted that the one who stirs up enmity by telling lies and making false statements will be punished even more.
Failing to keep oneself clean from urine indicates that the one who neglects prayer, for which cleansing oneself from urine is a requirement and condition will be punished even more. In the hadeeth of Shu’bah it says: “One of them used to eat the flesh of people,” which refers to backbiting or malicious gossip.
According to the hadeeth of Ibn Mas’ood (may Allaah be pleased with him) a man was struck with a whip and his grave was filled with fire because he offered a single prayer without having purified himself, and he passed by one who was being wronged and did not help him.
According to the hadeeth of Samurah in Saheeh al-Bukhaari, a person who told a lie that spread far and wide was punished.
A man who read Qur’aan then slept at night and did not act upon it by day was punished.
Adulterers and adulteresses are punished.
The one who consumes riba is punished in al-Barzakh, as the Prophet (peace and blessings of Allaah be upon him) testified.
According to the hadeeth of Abu Hurayrah (may Allaah be pleased with him), the heads of some people will be crushed with rock because they were too heavy for them to get up and pray.
Some will graze on al-daree’ and al-zaqqoom (horrid types of food in Hell) because they withheld the zakaah of their wealth.
Some will eat putrid, rotten meat because of their zina.
Some will have their lips cut off with iron scissors because they caused fitnah (fighting, civil war) with their words and their speech.
According to the hadeeth of Abu Sa’eed, those who committed these crimes will be punished. Some of them will have bellies as big as houses; they are those who consumed riba. Some will open their mouths and have stones thrown into them that will emerge from their nether regions; they are the ones who consumed orphans’ wealth. Some will be hung up by their breasts; they are the adulterers. Some will have their sides cut and will be fed with their own flesh; they are the one who engaged in backbiting. Some will have nails of copper with which they will scratch their faces and chests; they are the ones who impugned people’s honour.
The Prophet (peace and blessings of Allaah be upon him) said that the one who stole a cloak from the war booty will be wrapped in a cloak of fire in his grave. This is despite the fact that he was entitled to a share of the booty, so how about those who wrong others unlawfully?
The punishment of the grave is for sins of the heart, the eye, the ear, the mouth, the tongue, the stomach, the private parts, the hand, the foot, and the entire body.
Those who spread malicious gossip, tell lies, backbite, give false witness, slander those who are chaste and innocent, spread fitnah, promote bid’ah (innovation), say things about Allaah and His Messenger without knowledge, and speak in a reckless manner.
Those who consume riba, consume orphans’ wealth and consume haraam wealth such as bribes and the like.
Those who consume the wealth of their Muslim brothers unlawfully, or the wealth of non-Muslims living under Muslim protection, or consume intoxicants.
Adulterers, homosexuals, thieves, traitors, betrayers and plotters.
Those who consume riba, those who pay it, those who record it and those who witness it; those who enter into a marriage merely to divorce the woman so that it will become permissible for her to return to her former husband, and those for whom this is done; those who seek to waive the duties enjoined by Allaah and transgress His sacred limits.
Those who seek to harm the Muslims and seek to expose their faults.
Those who rule by something other than that which Allaah has revealed, those who issue rulings based on things which Allaah has not prescribed, and those who help others in sin and transgression.
Those who kill souls whom Allaah has forbidden us to kill, those who deny the names and attributes of Allaah, those who give their opinions and ideas precedence over the Sunnah of the Messenger of Allaah.
Those who wail for the dead and those who listen to them, those who will wail in Hell are those who sing songs that are forbidden by Allaah and His Messenger and those who listen to them. Those who build mosques over graves and set up lamps in them; those who try to take more when they take what they are owed and try to give less when they give what they owe.
Tyrants, the arrogant, those who show off, slanderers and backbiters, those who slander the salaf.
Those who go to soothsayers, astrologers and fortunetellers to ask them things and believe what they say.
Those who help wrongdoers, who have sold their Hereafter for the sake of others in this world.
Those who, if you remind them to fear Allaah do not pay any heed, but if you try to scare them by mentioning another person like themselves, they pay heed and refrain from what they are doing.
Those who are told of the words of Allaah and His Messenger but they do not pay any attention to it, but if they hear it from one of whom they think well, who may be right or wrong, they seize it and do not go against it.
Those to whom Qur’aan is recited but they are not affected by it, and it may be burdensome for them, but when they heard the “qur’aan” of the shaytaan or that which calls to zina (i.e., music) and words of hypocrisy, they feel good and it cheers them up, and they wish that the singer would not stop.
Those who swear by Allaah and tell lies, but when they swear by their shaykhs or relatives, or the life of one whom they love and respect, they will not lie, even if they are threatened and tortured.
Those who boast of their sins in front of their brothers.
Those from whom you do not feel that your possessions and dignity are safe. Those who engage in obscene speech, whom people shun for fear of their evil.
Those who delay prayer until the end of its time, and then peck out the prayer, remembering Allaah but little therein. Those who do not pay the zakaah of their wealth willingly. Those who do not perform Hajj even though they are able to, and do not do the duties required of them even though they are able to.
Those who are not cautious with regard to what they look at or say or eat or where they go, and they do not care what wealth they acquire, whether it is halaal or haraam.
Those who do not uphold the ties of kinship or show compassion towards the poor, widows, orphans, or animals, rather they forsake orphans and do not urge others to feed the poor. They show off to people, withhold small kindnesses, and seek out people’s faults and sins whilst ignoring their own.
All of these and their ilk will be punished in their graves for these sins, according to how great or small they were. Because most people are like this, most of the inhabitants of the graves will be punished, and those who succeed will be very few.
The outside of the grave is just earth, but inside it is regret and torment.
The outside may be earth and carved stones, whilst inside it is disaster and calamity, boiling with grief and sorrow like a kettle, and no wonder, when they no longer get what they want of their desires and wishes.
There are lessons in this world which need no further exhortation.
It calls out: O dwellers of the earth, you have focused on building a realm that will soon pass away, and you have neglected the realm to which you are moving quickly. You have built houses in which others will live and enjoy them, and you have neglected houses for which there are no other inhabitants but you.
This is the place where you will abide and bid farewell to work and toil. This is what matters, one of the gardens of Paradise or one of the chambers of Hell…
End quote from al-Rooh (95).