Abdullah bin Masud reported that when the verse "those who believe and do not mix their faith with wrongdoing" [Anam 6:82] was revealed, it weighed heavily on the companions of the Prophet ﷺ, and they said, "Which of us has not wronged himself?"The Messenger of Allah ﷺ said, "It is not as you suppose. It is only as Luqman said to his son, 'And when Luqman said to his son, while instructing him, My son, do not commit shirk with Allah. Indeed, shirk is a tremendous wrong'" [Luqman 31:13].
قال لما نزلت هذه الآية: {الذين امنوا ولم يلبسوا ايمانهم بظلم} شق ذلك على أصحاب النبي ﷺ، قالوا: أينا لم يظلم نفسه؟ فقال رسول الله ﷺ: ليس هو كما تظنون، إنما هو كما قال لقمان لابنه: {وإذ قال لقمن لابنه وهو يعظه يبني لا تشرك بالله إن الشرك لظلم عظيم} [سورة لقمان: ١٣].
Bukhari narrated it in the tafsir chapter (4629), and Muslim narrated it in the faith chapter (124), both of them through Sulayman Amash, from Ibrahim, from Alqama, from Abdullah bin Masud, who related it. The wording given is Muslim's, and Bukhari's wording is similar.