Zayd ibn Thabit reports that the Messenger of Allah ﷺ, while riding near a garden belonging to Banu al-Najjar, passed four, five or six graves. His mount became startled, and he asked who knew the people buried there. (Sahih Muslim, Book of Paradise, chapter on the deceased person's place)
A man said he knew them. When asked when they died, he answered that they had died in the period of polytheism.
The Prophet ﷺ then informed those present about punishment occurring in those graves.