Abu Masud and Huzaifa reported,

The Messenger of Allah ﷺ said, "There was a man among those who came before you who used to commit sins. When death approached him, he said to his family, 'When I die, burn my body, then grind it to dust, then scatter the dust into the sea on a stormy, windy day.'When he died, they did as he had instructed. But Allah عز وجل gathered him together in His hand and said to him, 'What made you do what you did?'He replied, 'Fear of You.'So Allah said, 'I have forgiven you.'"

Azami 11419

Sahih

عن أبي مسعود الأنصاري وحذيفة قالا

قال رسول الله ﷺ: كان رجل ممن كان قبلكم يعمل بالمعاصي، فلما حضره الموت قال لأهله: إذا أنا مت فأحرقوني، ثم اطحنوني، ثم ذروني في البحر في يوم ريح عاصف. قال: فلما مات فعلوا، قال: فجمعه الله عز وجل في يده قال له: ما حملك على ما صنعت؟ قال: خوفك، قال: فإني قد غفرت لك.

الأعظمي 11419صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Repentance and seeking forgiveness
Chapter
Comprehensive and general supplications
Section
Regarding one who feared Allah's punishment and ordered his body burned after death, not knowing that Allah is Forgiving and Merciful
Numbering
Jami al-Kamil 11419 (2nd edition)
Azami 11419