Shaykh Muhammad ibn ‘Uthaymeen (may Allah have mercy on him) said:
The questioning of the deceased in the grave is undoubtedly real, and the person sits up in his grave, speaks and is questioned.
If someone were to ask: the grave is narrow and confined, so how can he sit up?
The answer is:
With regard to matters of the unseen, the believer is required to accept them and believe, and not ask how or why, because no one asks about how or why except the one who has doubts. But the one who believes and whose heart is content with what Allah and His Messenger say, will accept it and say, Allah knows best about how that happens.
The connection of the soul to the body in death is different from its connection in life. The connection between body and soul may vary in ways that man cannot understand, and the body’s connection to the body after death cannot be compared to the connection in life. When a person dreams, he sees himself coming and going, travelling, speaking to people, meeting people both living and dead; he may see himself having a beautiful garden, or a dark and frightening house; he may see himself riding in a comfortable car, or riding in an uncomfortable car. All of that may happen, even though he is in his bed and nothing has changed, and even the blanket covering him has not changed, but nevertheless we feel that in a real sense. But the connection of the soul to the body after death is different to its connection when one is awake and when one is asleep. It is different and we do not understand it. So a person can sit up in his grave and be questioned, even though the grave is narrow and confined.
Similarly this was narrated in a saheeh hadeeth from the Prophet (peace and blessings of Allah be upon him); he conveys the message and we have to believe and submit. Allah says (interpretation of the meaning):
“But no, by your Lord, they can have no Faith, until they make you (O Muhammad) judge in all disputes between them, and find in themselves no resistance against your decisions, and accept (them) with full submission”
(May Allah Save Us From The Punishment Of the Grave)
(Source - Islam Q&A)