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.
If a person is forced to utter the word of disbelief, he does not become a disbeliever by saying it as Allah Says (what means): {Whoever disbelieves in Allah after his belief except for one who is forced [to renounce his religion] while his heart is secure in faith. But those who [willingly] open their breasts to disbelief, upon them is wrath from Allah, and for them is a great punishment.} [Quran 16:106]
Al-Bayhaqi reported in as-Sunan al-Kubra that Ibn Abbas, said about this verse: “Allah informed us that whoever disbelieves after his belief, then the wrath of Allah is upon him, and that he has a great punishment; as for he who is compelled and uttered with his tongue, but his heart is firm with faith, so that he may thereby be saved from his enemy, then there is nothing wrong with him, for Allah, Glory be to Him, only holds the servants accountable according to what they believe in their hearts.”
Al-Haakim reported in al-Mustadrak and he authenticated it – and ath-Thahabi agreed with him – from Mohammed ibn ‘Ammar ibn Yasser who said: “The polytheists took ‘Ammar ibn Yasser [i.e. his father, the father of Muhammad] and did not set him free until he insulted the Prophet and praised their gods, and then they set him free. When he came to the Messenger of Allah the latter asked him: “What happened to you?” He said: ‘Evil, O Messenger of Allah, I was not set free until I insulted you, and I praised their gods.’ He said: “How do you find your heart?” He said: ‘Assured with faith.’ He said: ‘If they return, then return again.” This is a Saheeh Hadeeth on the conditions set by Al-Bukhari and Muslim, but they did not report it.
Allah knows best.