All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
The report you quoted is not a Prophetic Hadith, maintaining that though it is recorded in Saheeh Al-Bukhari, it is a Mawqoof Hadith (i.e., its chain of transmission stops at Ibn ʿAbbas – which means it is a statement of Ibn ‘Abbas, may Allaah be pleased with him, and not a saying of the Prophet).
Al-Bukhari has narrated it in Kitab At-Tafaseer particularly Chapter "Allahu As-Samad", and Surah Qul A’oodhu bi Rabbi An-Naas [Quran 114]. He narrates fromIbn ʿAbbas that he said, “When the fetus is delivered, the devil touches it. When Allah, the Exalted, is mentioned, it withdraws. But, if Allah, the Almighty, is not mentioned, it would couch at the heart of the son of Adam.” [End of quote]
In his Fath Al-Bari, ibn Hajar said, “The chain of transmission of this Hadith to Ibn ʿAbbas is weak. This report is narrated by At-Tabari and Al-Hakim and its chain of transmission includes Hakim ibn Jubayr a weak narrator.
The Hadith is narrated with the following wording, 'No fetus is born unless the retreating whisperer couches on its heart. So, if Allah, the Exalted, is mentioned, it would withdraw; otherwise, it would whisper.' We have also narrated it in Chapter Adh-Dhikr on the authority of Jaʿfar ibn Ahmed ibn Faris with another chain of transmission also attributed to Ibn ʿAbbas stressing that this Isnaad includes Muhammad ibn Humayd Ar-Razi . It reads, 'The devil places its mouth on the heart of the son of Adam. So, if he neglects observance of the Dhikr of Allah, it would whisper; otherwise, it would retreat and withdraw.' Scholars disagree on the authenticity of this chain of transmission. Saʿeed ibn Mansoor furthermore narrated it in another way on the authority of Ibn ʿAbbas with the following wording, 'Whenever the son of Adam is born, the devil couches on its heart. So, if it becomes thoughtful and mentions the Name of Allah, the devil would retreat; otherwise, it would whisper.”
Allah knows best.