Some people used to question the Messenger of Allah ﷺ mockingly. One man would ask, "Who is my father?" Another, whose camel had wandered off, would ask, "Where is my camel?" So Allah revealed concerning them this verse, "You who believe, do not ask about things which, if shown to you, would distress you" [Maidah 5:101], until the end of the entire verse.
كان قوم يسألون رسول الله ﷺ استهزاء. فيقول الرجل: من أبي؟ ويقول الرجل تضل ناقته: أين ناقتي؟ فأنزل الله فيهم هذه الآية {يايها الذين امنوا لا تسألوا عن اشيآء ان تبد لكم تسؤكم}. حتى فرغ من الآية كلها.
Bukhari reported it in Tafsir (4622), from Fadl bin Sahl, he said, Abu Nadr told us, Abu Khaythama told us, Abu Juwayriyah told us, from Ibn Abbas, who said, then he mentioned it.It was already noted in the book on Hajj that the reason for the revelation of this verse was the question about Hajj. But the more well-known account is what we have mentioned here. There is no obstacle to there being multiple reasons for revelation.This noble verse and these hadiths indicate the disapproval of asking about matters one has no need to know, matters whose answer would distress the questioner, and this has been established in the sahih.