Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
bukhari:1340ʿUthmān b. Abū Shaybah > Jarīr > al-Shaybānī > al-Shaʿbī > Ibn ʿAbbās

The Prophet ﷺ offered the funeral prayer of a man one night after he was buried, he and his companions stood up (for the Prayer). He had asked them about him before standing, saying, "Who is this?" They said, "He is so and so and was buried last night." So all of them offered the funeral prayer.  

البخاري:١٣٤٠حَدَّثَنَا عُثْمَانُ بْنُ أَبِي شَيْبَةَ حَدَّثَنَا جَرِيرٌ عَنِ الشَّيْبَانِيِّ عَنِ الشَّعْبِيِّ عَنِ ابْنِ عَبَّاسٍ ؓ قَالَ

صَلَّى النَّبِيُّ ﷺ عَلَى رَجُلٍ بَعْدَ مَا دُفِنَ بِلَيْلَةٍ قَامَ هُوَ وَأَصْحَابُهُ وَكَانَ سَأَلَ عَنْهُ فَقَالَ مَنْ هَذَا فَقَالُوا فُلاَنٌ دُفِنَ الْبَارِحَةَ فَصَلَّوْا عَلَيْهِ  


See similar narrations below:

Collected by Ibn Ḥibbān

ذِكْرُ إِبَاحَةِ الصَّلَاةِ عَلَى الْقَبْرِ وَإِنْ أَتَى عَلَى الْمَدْفُونِ لَيْلَةٌ

ibnhibban:3091ʿImrān b. Mūsá b. Mujāshiʿ > ʿUthmān b. Abū Shaybah > Jarīr > al-Shaybānī > al-Shaʿbī > Ibn ʿAbbās

[Machine] The Messenger of Allah ﷺ prayed upon the grave of a man after he was buried at night. He and his companions got up and asked about him. They were told that so-and-so was buried yesterday, so they prayed for him.  

ابن حبّان:٣٠٩١أَخْبَرَنَا عِمْرَانُ بْنُ مُوسَى بْنِ مُجَاشِعٍ قَالَ حَدَّثَنَا عُثْمَانُ بْنُ أَبِي شَيْبَةَ قَالَ حَدَّثَنَا جَرِيرٌ عَنِ الشَّيْبَانِيِّ عَنِ الشَّعْبِيِّ عَنِ ابْنِ عَبَّاسٍ قَالَ

«صَلَّى رَسُولُ اللَّهِ ﷺ عَلَى قَبْرِ رَجُلٍ بَعْدَمَا دُفِنَ بِلَيْلَةٍ قَامَ هُوَ وَأَصْحَابُهُ وَكَانَ قَدْ سَأَلَ عَنْهُ قَالُوا فُلَانٌ دُفِنَ الْبَارِحَةَ فَصَلُّوا عَلَيْهِ»