When a person finds themselves in a crisis, and they find themselves overcome with fear and grief, they turn to Allah with a heart that is like no other person. The depth of sincerity that they display and the desperate need they have for Allah’s Mercy is so strong and pure that their du’a is answered regardless of whether they are a Muslim or not.
As Allah says of Himself:
“Is not He (the One) who responds to the distressed one when he calls out to Him?” (Surah al-Naml:62)
Al-Qurtubi wrote: “Allah had guaranteed the response of the du’a of the one in distress, as He Himself informed us of this (guarantee). And the reason for this is that the one in distress will turn to Him with a pure sincerity, cutting his hope off from all other sources. And sincerity to Him is the cause of (gaining) His protection, regardless of whether it emanates from a kafir or Muslim, evil or pious!”