The concept of punishment of the grave is narrated by over 40 companions (ra) with no disagreement by any companions. It seems compelling that the concept was taught by the Prophet (saw). Muslim Scholarship discussed the issue in detail and achieved a broad agreement.
Abi Hayan quotes Abu Hanifa (the founder of Hanafi madhhab) saying:
إِذَا أَجْمَعَتْ الصَّحَابَةُ سَلَّمَنَا لَهُمْ ، وَإِذَا جَاءَ التَّابِعُونَ زَاحَمْنَاهُمْ ، لِأَنَّهُ كَانَ مِنْهُمْ
"When the companions unanimously agree, we accept their opinion; but when their successors unanimously agree, we can question them because (Abu Hanifa) was one of them" (Abi Hayah, al-Bahr al-Muhitt, Vol. 7, p. 320)
Shafi'i stated a similar statement as Zarkashi said in al-Bahr al-Muhitt, Vol. 8, p. 56, and al-Mahbubi mentioned similar thing in at-Talwih 'ala, Attawdih, Vol. 2, p. 109.
The concept of punishment of the grave is narrated, as I just mentioned above, by over 40 companions (ra) with no disagreement by other companions. So such concept must have been preached by the Prophet (saw).
Abu al-Hassan al-Ash'ari said:
وَأَجْمَعُوا عَلَى أَنَّ عَذَابَ الْقَبْرِ حَقٌّ وَأَنَّ النَّاسَ يُسْئَلُونَ فِي قُبُورِهِمْ بَعْدَ أَنْ يُحْيَوْا فِيهَا .
"They Unanimously agree on the reality of punishment of the grave and on the questioning in their grave after coming back to life again in it (spiritually)." (Risalah ila Ah lath-Thaghr, pp. 88-89)
Ibn Taymiyyah said:
الْعَذَابُ وَالنَّعِيمُ عَلَى النَّفْسِ وَالْبَدََنِ جَمِيعًا بِاِتِّفَاقِ أَهُلِ السُّنَّةِ وَالْجَمَاعَةِ
"Ahl-as-Sunah wa al-Jama'ah unanimously agree that punishment and blissing would be on both spirit (nafs) and body " (Majmu' al-Fatawa, Vol. 4, p. 282, Vol. 4, p. 262)
The Ijma' is also stated by al-Manawi, Nawawi, Ibn Hajar and others.
Abi Hayah, al-Bahr al-Muhitt.
al-Mahbubi, at-Talwih 'ala , Attawdih.
Abu al-Hassan al-Ash'ari, Risalah ila Ah lath-Thaghr.
Ibn Taymiyyah, Majmu' al-Fatawa.