Shaykh Ashraf Ali Thanwi (RA) relates,
In a certain country, two people were on their deathbeds: one a Muslim, the other a non-muslim. The desire arose in the non-muslim's heart to eat fish...and despit having a pond in his garden; there were no fish present. A thought also arose in the Muslim's heart...to eat fresh ripe olives that were hanging upon a tree in his garden.
Allah commanded one of his angels,"In so-and-so town, a non-muslim is about to die and his heart desires to eat fish.Go and place a fish in his pond so that his wish is fulfilled."
To another angel, He commanded,
"In so-and-so town a Muslim is about to die and his heart desires to eat ripe olives which are in his garden. Go and destroy these olives thereby preventing fulfillment of his wish."
Accordingly, both angels enacted their respected missions. Upon returning, they began to question each other's task; puzzled they began to fathom a reason. Unable to understand they asked Allah,
"O Allah! Whilst we have carried out Your Command, we fail to comprehend why a Muslim, who obeys Your ahkams (laws and rulings) and who had olives in his ownership was deprived from eating them? Moreover, the non-muslim, who disobeys and disbelieves in You and who did not even have a fish, his wish was fulfilled, why?"
"You are unaware of the Hikmat (Wisdom) behind Our Commands, the reality is Our aatitude towards the kuffar and Muslims is very different. Since the kuffar(non-muslims) too perform good deeds in this world, for example, they give Sadaqah (charity) to some needy cause, but, because these amals(actions) are not acceptable to Us in the Akhirah (Hereafter), therefore we reward them fully in the dunya. Now when he appears before Us in the Akhirah, any good deeds will already have been rewarded; We will own him nothing. Our behaviour towards the Muslims is different. We desire that any penalisation for sins he had committed takes place in the Dunya (World); thereby when he arrives to meet Us, he is pure and clean from sins!
Accordingly, whatever good this kafir had performed, We had rewarded him in the Dunya... except for one deed. Now, he was about to return to us, and when this desire arose in his heart to eat fish, We decided to fulfill his wish thereby settling his 'account'. With regards to the Muslim, during the time of his illness all his sins were forgiven...except one! Had he left the Dunya in this state, that one sin would have remained in his Book of Deeds. This is why We decided to destroy his olives and place a sorrow upon his heart by preventing him from eating...thus forgiving him his sin. He now returns to us pure and clean!"
None from the creation is able to fully understand the Hikmat (Wisdom) of Allah, our small finite intellect is unable to comprehend reasons behind the modus operandi(mode of operating) of this universe.
Taken from: Ashraf's advice upon death