Having revealed various precepts that cover all sides of life and death, Allah conditioned their obligation on potentiality. Thus, the Islamic Shari`ah is thoroughly concerned with people’s capability, and it rightfully considers the concurrent and surrounding conditions and issues for every case, and with a practical and moderate scope.
Answering the question, the Fatwa Council of Dar Al-Ifta of Egypt stated,
According to Islamic Shari`ah, each corpse must be laid down in a separate lahd (grave with a lateral hollow) or shaqq (a simple trench dug down in the middle of the floor of the grave).
An exception is made when the graves become full. It is authentically reported that Prophet Muhammad (peace and blessings be upon him) buried two or three of the martyrs of the Battle of Uhud in a single grave. Also, it is noted that there must be separate graves for men and women.
Based on the above and in reference to the question, when necessity calls for burying more than one individual in a single grave, it is permissible to construct multiple levels inside the grave to accommodate the increasing number of dead persons.