Hisham bin Amir reported,

We complained to the Messenger of Allah ﷺ on the day of Uhud, saying, "Messenger of Allah, digging a grave for each person is too difficult for us."The Messenger of Allah ﷺ said, "Dig, make the graves deep, dig them well, and bury two or three in a single grave."They asked, "Whom shall we put first, Messenger of Allah?"He replied, "Put first the one who knew the most of the Quran."He said, Ubayy was the third of three placed in a single grave.

Nasai 2012

Sahih

أخبرنا محمد بن بشار قال حدثنا إسحق بن يوسف قال حدثنا سفيان عن أيوب عن حميد بن هلال

عن هشام بن عامر قال

شكونا إلى رسول الله ﷺ يوم أحد فقلنا يا رسول الله الحفر علينا لكل إنسان شديد فقال رسول الله ﷺ احفروا وأعمقوا وأحسنوا وادفنوا الاثنين والثلاثة في قبر واحد قالوا فمن نقدم يا رسول الله قال قدموا أكثرهم قرآنا قال فكان أبي ثالث ثلاثة في قبر واحد

النسائي 2012صحيح
Contents
Reference
Commentary
Ayat
Collection
Sunan Nasai Sughra
Book
Funerals
Chapter
What is recommended regarding deepening the grave
Numbering
Darussalam 2012
Nasai 2012