The Quran speaks of a barrier (barzakh) behind which the dead remain until the day they are raised. It says that Pharaoh's people are exposed to the Fire morning and evening, and that Allah keeps the believers firm with the firm word, in this life and in the next. The Prophet ﷺ described two angels who make the dead person sit up and ask what they used to say about Muhammad ﷺ. The believer answers that he is the servant of Allah and His messenger and is shown a place in Paradise in place of one in the Fire. The one who rejected the message or only pretended to believe says only 'I do not know, I said what people said', and the hadith describes a place of distress for him.
Muslims accept this as a matter of the unseen (ghayb): it is reported by sound hadith, it cannot be checked with the senses, and an opened grave shows nothing, because barzakh is not like this world. Scholars differ on exactly how soul and body share in it, and Muslims are taught not to picture it by earthly standards. The Prophet ﷺ himself used to ask Allah for protection from the punishment of the grave in his supplications, which shows that this is meant to be taken seriously, and that the believer's answer is to turn to Allah.
This is not the final judgment, which comes later, and it does not mean that Allah is eager to punish. The questions are simple and they are answered by those who truly lived by what they believed. Muslims hope for mercy there, as everywhere, and the belief is meant to make a person take life seriously: what we carry into the grave is not wealth or status but what we did and what we believed.