Sunan an Nasai 324
The Book of Purification
أَخْبَرَنَا مُحَمَّدُ بْنُ عَبْدِ الأَعْلَى، قَالَ حَدَّثَنَا أُمَيَّةُ بْنُ خَالِدٍ، قَالَ أَنْبَأَنَا شُعْبَةُ، أَنَّ مُخَارِقًا، أَخْبَرَهُمْ عَنْ طَارِقٍ، أَنَّ رَجُلاً، أَجْنَبَ فَلَمْ يُصَلِّ فَأَتَى النَّبِيَّ صلى الله عليه وسلم فَذَكَرَ ذَلِكَ لَهُ فَقَالَ " أَصَبْتَ " . فَأَجْنَبَ رَجُلٌ آخَرُ فَتَيَمَّمَ وَصَلَّى فَأَتَاهُ فَقَالَ نَحْوَ مَا قَالَ لِلآخَرِ يَعْنِي " أَصَبْتَ " .
It was narrated from Tariq that a man became Junub and did not pray, then he came to the Prophet (ﷺ) and mentioned that to him. He said:"You did the right thing." Another man became Junub and performed Tayammum and prayed, and he came to him and he said something similar to what he had told the other man - meaning, you did the right thing
Grading: Abu Ghuddah: Sahih Isnaad · Al-Albani: Sahih Isnaad · Zubair Ali Zai: Sahih
Text from the public-domain hadith-api dataset. Numbering follows that dataset and can differ by a few from some printed editions — check the wording, not only the number.