The Prophet ﷺ said, "There is no child born but that Satan touches him at the moment of his birth, so he cries out at Satan's touch, except for Mary and her son."Then Abu Hurairah would say, "Recite, if you wish, 'And I seek refuge for her with You, and for her offspring, from Satan the accursed'" [Al Imran 3:36].
أن النبي ﷺ قال: ما من مولود إلا والشيطان يمسه حين يولد، فيستهل صارخا من مس الشيطان إياه، إلا مريم وابنها ثم يقول أبو هريرة: واقرؤوا إن شئتم: {وإني أعيذها بك وذريتها من الشيطن الرجيم}.
Bukhari narrated it in the tafsir (4548) and Muslim in al-Fadail (2366), both through the route of Mamar, from Zuhri, from Saeed bin Musayab, from Abu Hurairah, who mentioned it. The wording given is Bukhari's, and Muslim's wording is similar.As for His saying, "And Allah knows best what she delivered, and the male is not like the female" [Al Imran 3:36], this is a parenthetical statement. In it, Allah tells us that He has no need to inform her or anyone else, rather He, glory be to Him, knew that the newborn would be a female before her mother knew it and before she gave birth to her. He also knew that this female was better than the male whom the wife of Imran had wished for, since a male would be stronger, more capable, and more suited to serving Bayt al-Maqdis. She had vowed to Allah that whatever was in her womb would be dedicated to that service.But this newborn girl was better than that male would have been, because she would become the mother of a great prophet, and she would be among the foremost women of Paradise. So these words are from Allah , not from the wife of Imran expressing regret that she had given birth to a girl.