I asked, or someone asked, the Messenger of Allah ﷺ, "Which sin is greatest in the sight of Allah?"He said, "That you set up a rival to Allah, when it is He who created you."I said, "Then what?"He said, "Then that you kill your child out of fear that he will eat with you."I said, "Then what?"He said, "That you commit adultery with your neighbor's wife."The narrator added that this verse was revealed confirming what the Messenger of Allah ﷺ had said, "Those who do not call upon another god besides Allah, nor kill the soul which Allah has forbidden except by right, nor commit adultery. Whoever does that will meet a penalty" [Furqan 25:68].
سألت أو سئل رسول الله ﷺ أي الذنب عند الله أكبر؟ قال: أن تجعل الله ندا وهو خلقك. قلت: ثم أي؟ قال: ثم أن تقتل ولدك خشية أن يطعم معك. قلت: ثم أي؟ قال: أن تزاني بحليلة جارك. قال: ونزلت هذه الآية تصديقا لقول رسول الله ﷺ: {الذين لا يدعون مع الله الها اخر ولا يقتلون النفس التي حرم الله الا بالحق ولا يزنون ومن يفعل ذلك يلق اثاما} [سورة الفرقان: ٦٨].
Bukhari related it in the tafsir (4761), and Muslim in the faith chapter (142:86), both from the hadith of Amash, from Abu Waail, from Abu Maysara, from Abdullah, who said, and then he mentioned it. The wording given here is Bukhari's.