Reference: al-Bukhaaree in at-Taareekh, Ibn Maajah, Ahmad and others. It is a hasan hadeeth as indicated by Shaykh al-Albaanee in Silsilah al-Ahaadeeth as-Saheehah.
On the authority of al-Baraa ibn ‘Aazib (radhi-yAllaahu ‘anhu) who said: While we were with the Messenger of Allaah ﷺ, he suddenly looked towards a group (of people) and said:
For what reason have they gathered here?
It was said: In order to dig a grave.
So the Messenger of Allaah ﷺ became alarmed and startled and he quickly went ahead of his Companions until he reached the grave, then he knelt upon it, and I turned my face towards him ﷺ, in order to see what he was doing. He ﷺ cried until the earth became wet with his tears, then he turned to us and said:
O my brothers! Prepare for a day like this.