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 Messenger of Allah ﷺ, and they said, "Which of us does not wrong himself?"The Messenger of Allah ﷺ replied, "It is not as you suppose. It means what Luqman said to his son, 'My son, do not commit shirk with Allah. Indeed shirk is a terrible wrong'" [Luqman 31:13].
لما نزلت {الذين آمنوا ولم يلبسوا إيمانهم بظلم} [سورة الأنعام: ٨٢] شق ذلك على أصحاب رسول الله ﷺ وقالوا: أينا لا يظلم نفسه؟ فقال رسول الله ﷺ: ليس هو كما تظنون، إنما هو كما قال لقمان لابنه: {يبنى لا تشرك بالله إن الشرك لظلم عظيم}
Bukhari related it in the Tafsir (4776), and Muslim in the Iman (124), both of them from the hadith of Amash, from Ibrahim, from Alqama, from Abdullah, who related the hadith. The wording given is Muslim's, and Bukhari's wording is similar.