Uqba bin Harith reported,

I prayed the Asr prayer with the Prophet ﷺ. When he gave the closing salam, he stood up quickly and went in to one of his wives, then came back out. He saw the astonishment on the faces of the people at his haste, so he said, "I remembered, while I was in prayer, some gold we had, and I disliked that it should remain with us into the evening or through the night, so I ordered it to be distributed."

Bukhari 1221

Sahih

حدثنا إسحاق بن منصور حدثنا روح حدثنا عمر هو ابن سعيد قال أخبرني ابن أبي مليكة

عن عقبة بن الحارث رضي الله عنه قال

صليت مع النبي ﷺ العصر فلما سلم قام سريعا دخل على بعض نسائه ثم خرج ورأى ما في وجوه القوم من تعجبهم لسرعته فقال ذكرت وأنا في الصلاة تبرا عندنا فكرهت أن يمسي أو يبيت عندنا فأمرت بقسمته

البخاري 1221صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Work during prayer
Chapter
A man thinking about something during prayer
Numbering
Darussalam 1221
Bukhari 1221