Why was my prayer not answered?
Here are two reasons why prayers are not answered:
You ask and do not receive, because you ask amiss, that you may spend it on your pleasures.  Adulterers and adulteresses! Do you not know that friendship with the world is enmity with God? Whoever therefore wants to be a friend of the world makes himself an enemy of God. 1 Peter 3:7
Husbands, likewise, dwell with them with understanding, giving honor to the wife, as to the weaker vessel, and as being heirs together of the grace of life, that your prayers may not be hindered.
And here is why they are:
If you abide in Me, and My words abide in you, you will ask what you desire, and it shall be done for you.
Mark 11:24 NKJV
Therefore I say to you, whatever things you ask when you pray, believe that you receive them, and you will have them.
I would like to add that I believe that when we pray a prayer for someone and they die, it is not necessarily because our prayers were not heard. Death comes to us all because of sin. We have not yet put on immortality and will not till we "awaken in his likeness".
Sometimes, we just do not ask God how we should pray and that is part of abiding, isn't it? We cannot undo what God has done. He is the alpha and omega of everything and everyone. If he has given a man a certain number of years and we try to change that outside of his will, we are attempting to put ourselves above Him. We cannot do that. Nevertheless, God has at times given special grace to a man for a reason, as he did for King Hezekiah, when he humbled himself. Isaiah 38:1-3,5
In those days Hezekiah was sick and near death. And Isaiah the prophet, the son of Amoz, went to him and said to him, “Thus says the LORD: ‘Set your house in order, for you shall die and not live.’”  Then Hezekiah turned his face toward the wall, and prayed to the LORD,  and said, “Remember now, O LORD, I pray, how I have walked before You in truth and with a loyal heart, and have done what is good in Your sight.” And Hezekiah wept bitterly.  “Go and tell Hezekiah, ‘Thus says the LORD, the God of David your father: “I have heard your prayer, I have seen your tears; surely I will add to your days fifteen years.
Our Father in Heaven, help us never to be so foolish as to point a finger at You. You have given so much to save us. Thank you for that. We trust you that when our prayer is not answered in the way we would like it to be, it is for Your good reason. Give us grace so we may humble ourselves, and accept that. But we also ask you to help us abide in you, so that we know we have sinned, we repent from it and walk in the light again. We ask you to give us your Holy Spirit that we may pray according to your will and our prayers may not be hindered but that we will have the things we ask.