All Christians pray to God. Prayer is not just something we do to get something out of God. Prayer is a time we spend in fellowship with God. However, petitions (asking God to do things) is only one type of prayer we Christians pray. The Bible says "Do not be anxious about anything, but in every situation, by prayer and petition, with thanksgiving, present your requests to God." (Philippians 4:6) And often times, God answers our pleas and does what we ask of Him. For example, one of the Psalmists wrote "Then they cried out to the LORD in their trouble, and he brought them out of their distress. He stilled the storm to a whisper; the waves of the sea were hushed. They were glad when it grew calm, and he guided them to their desired haven." (Psalm 107:28-30)
However, we all know that God doesn't always do what we ask Him to. Sometimes He says no. Sometimes what we ask God to do doesn't come to pass. Why is this? Why doesn't God always answer our prayers? Why is it that God refuses us?
There are several reasons in scripture given for why God doesn't answer peoples' prayers. Not all of the reasons are applicable to all people in all situations. The reason(s) why God says "no" differ from person to person and circumstance to circumstance. It's a case-by-case basis, so don't think these reasons necessarily apply to you. They might, and for some of the reasons given below, self-examination will help you know whether they do or not. Anyway, what are the various reasons given for why there are unanswered prayers.
1: Heavenly Father Knows Best
As a Maximally Great Being, God is omniscient. The Bible teaches that God knows everything (see 1 John 3:20, John 21:17) that His understanding has no limit (Psalm 147:5), because of this, He knows and sees what everyone in the world is currently doing (Proverbs 15:3), and even knows everything that will occur in the future (Psalm 139:1-6). God knows everything that could happen, would happen , and will happen. God has knowledge of all true propositions. Because of this, God is in a much better position to judge than we are. Because God is omniscient, it follows that He knows what's best for us.
Perhaps that thing we're praying for would do us harm, and bring us long term unhappiness. For example, suppose a young woman is praying that a young man she is dating decides to commit to her by asking her to marry her. She prays "God, please move in his heart to propose. I love him and want to spend the rest of my life with him." But suppose if this woman (we'll call her Joan) marries her boyfriend (whom we'll call Shawn), then her future would be terribly miserable. Unbeknownst to Joan, Shawn is a sex addict. He watches porn every night, and he picks up prostitutes on a weekly basis. Shawn has been able to keep this all a secret from everyone, but not from God. If Joan marries Shawn then Shawn would end up giving her an STD he caught from one of his hookers. Moreover, Shawn will abandon Joan and the kids down the road leaving them to fend for themselves. You see, Joan's income isn't as good as John's, so Joan and her kids were largely depended on Shawn. As a result of Shawn's leaving, Joan descends into deep poverty. Out of desperation, she gets a job as a prostitute herself in order to make ends meet. God knows that all of this would occur if Joan marries Shawn. Because God cares about Joan and wants a better life for her, he decides to say "no" to her prayers.
Or consider this example: Let's say that a man named Rick has an important interview for a high paying job. He prays to God that he does well in the interview and that he gets the job. But on the day Rick is supposed to meet with his would-be employer, his car won't start! He can't go anywhere! He could call an UBER cab or a friend to take him, but by the time they reach his house, pick him up, and take him to the office, he will have been late. You see, when Rick entered his car, he was already running late. There was a short black out the previous night, so Rick's alarm clock went off and never came back on, so Rick overslept. There is no conceivable way for Rick to get to the interview, so Rick prays and prays and prays for God to make his car start. After 20 minutes of praying and turning the key, Rick angrily storms into his house. He misses the interview and doesn't get the job.
Why did God allow Rick to not get this job? Doesn't He know how badly he needed it? Doesn't he know that the Job Rick currently has is barely enough to put food on the table? God knew that if Rick had left the house, he would have been in a fatal car accident. By allowing things to come about as they did, God saved Rick's life. Moreover, God also knew that 10 years after this event, Rick would be in the just-right place at the just-right time to stop a suicide. Ten years from that date, Rick would be walking down the street and see a man about to jump from a bridge. Rick manages to not only talk the man out of committing suicide, but he also leads him to Christ. If God answered Rick's prayer for his car to start, he would have died, and if Rick died, he wouldn't have been able to talk that man 10 years later out of committing suicide and to give his life to Christ. And if Rick hadn't lead that man to Christ, he would have gone through with his suicide, died without knowing Christ, and would have gone to Hell. By not answering Rick's prayer ("God, please make my car start"), he not only saved Rick's life, but he saved another man's soul.
Every event that occurs sends a ripple effect throughout history. God knows what would happen if He acted to intervene to stop a certain event from occurring. Every event that occurs in the present has a radical effect on the future in some way or another. This is why we're told in Time Travel science fiction novels not to tamper with the events of the past. If we do, the future can be altered in ways we cannot even imagine. Just as, in Chaos Theory, a Butterfly fluttering its wings on a Twig in South Africa can set in motion forces that result in a Hurricane over the Pacific Ocean.
It could be that God refused to answer some prayer of some person in 1587 A.D because He knew that if He did, then a chain of events would follow, culminating in the Nazis winning World War II and exterminating everyone who disagreed with them. When God says "No" to our prayers, whatever they may be for, we need to trust Him. He's got a better vantage point than we do. Perhaps the future is better off if a prayer goes unanswered in the past.
2: You're Praying With Wrong Motives
While God might be saying "No" because saying "Yes" would usurp His overall plan for human history, or alter the future in negative ways, in some cases, that isn't the reason at all. In some cases, the reason God doesn't answer a prayer is that it's asked with wrong motives. The Bible says that God knows what’s in our hearts (see 1 Samuel 16:7, Deuteronomy 31:21, Psalm 44:21, Psalm 139:2, Proverbs 15:11). James 4:3 says "When you ask, you do not receive, because you ask with wrong motives, that you may spend what you get on your pleasures."
The reason God didn't do what you asked of Him may be that your motive for asking was impure. Do some introspection to see if this is the case. What would an example of a wrong-motive-prayer be? Well, suppose a woman is praying for her son to do well at a local Spelling Bee. She wants her son to win so she asks God to help him remember how to correctly spell all of the words the judges will present to him. With the information I already presented you with, you might think she's praying this prayer because obviously she loves her son and wants him to succeed, but in reality, she wants her son to win because she wants something to brag about to her group of friends. She wants to brag about how smart her son is. Her motive is impure, so God refuses to answer the prayer. Her son forgets how to spell more words than he remembers and loses the spelling bee.
If a man prays for something bad to happen to people who hurt him, this would be an example of an impure motive. Jesus said to love our enemies (Matthew 5:44), and praying for harm to come upon someone is certainly not loving. "Do not rejoice when your enemy falls, and let not your heart be glad when he stumbles, lest the LORD see it and be displeased, and turn away his anger from him." (Proverbs 24:17-18)
Another example would be if a person struggled with masturbation addiction and prayed for God to help him stop, but the only reason he wants to stop it because he feels like he has to in order to be a good Christian. He doesn't want to stop because He thinks it displeases God or because he doesn't want anything to come between him and God, but because he feels obligated to.
3: God Cannot Answer People Praying For Mutually Exclusive Things
In some cases, God won't be able to answer your prayer because that would mean saying "no" to someone else. For example, during a football game, there are people on both sides praying for their favored team to win. Obviously, God cannot answer the prayers of both the Clemson and the Gamecocks fans. Someone has to win and someone has to lose. God, out of logical necessity, must say "yes" to one and "no" to another.
If two people are applying for the same job, and both are praying that they get hired, God has to say "yes" to one and "no" to the other. It's logically impossible for God to say "yes" to both people. You might as well ask God to create a square circle, or a one-ended stick, or a married bachelor.
4: God May Not Be Able To Answer Your Prayer Without Interfering With Free Will
The Bible teaches and implies in various places that people have free will (e.g Deuteronomy 30:19, Joshua 24:15, 1 Corinthians 10:13). Answering your prayer, depending on what it is you're praying for, may be infeasible for God to answer because it would involve forcing or determining a person to do something they don't want to do. For example, if you're praying for a girl to like you and go out with you, God would have to override her free will to make that happen. He would have to control her like a puppet. If she isn't into you, she isn't into you, and God can't do anything about it without causally determining her like a puppet.
Now, as a Molinist, I do believe that God can not only work around free will, but through it. Perhaps God, knowing you would pray for this woman to be interested in you if He created you in this circumstance, would choose to actualize a world where the woman you're interested finds herself in a circumstance such that even though she isn't currently interested in you, she becomes interested in you at some point. Perhaps God knew "If Bob were in circumstance X, He would be interested in Julia" and "If Bob is interested in Julia, he would freely choose to pursue her affection" and "If Bob pursues Julia's affection, he would freely choose to write her a love song", and "If Bob writes Julia a love song, she would not fall for him, in fact she would consider it a little desperate." and "But if Bob performs the love song a T, he would be in the just-right place at the just-right time to take Julia to the hospital to see her sister because immediately after he performs the song, Julia would receive a phone call from her father telling her that her sister was in a terrible accident, so Bob takes Julia because she'd be too upset to drive there herself." and Bob would be a shoulder for Julia to cry on, and because he so kind to her during this terrible time, Julia actually develops feelings for him. However, Julia spends much time in the car ride over to the hospital and in the waiting room in prayer, praying for her sister to survive. God, wanting to answer Julia's prayer as well, knows "If Samuel Johnson were born in this town at Time X, then he would freely choose to become a doctor when he grows up" and "If Samuel Johnson becomes a doctor, he would freely choose to work at the hospital Julia's sister would be in and would be the one to operate on her." and "Since Dr. Johnson is the most skilled operator in town, he would save her life whereas other doctors in his situation would fail." Julia's sister survives, and Bob has a new girlfriend named Julia.
If God were to place Bob in circumstance X, all of these circumstances would come about. God orchestrated this whole thing because He knew logically prior to creating the universe that Bob would pray for Julia to fall for him if he were in the circumstance that He was in. God can meticulously control human history and preserve free will at the same time by means of His middle knowledge. In the above hypothetical scenario, the entire story played out under the providential control of God, yet all the actors chose their actions freely. God didn't make these people do what they did, He just knew that they would choose what they chose if they were to find themselves in these circumstances. Moreover, the reason God chose to orchestrate the aforementioned events was to answer the prayer of Bob that Julia would fall in love with him. Even though free will choices were involved, God answered the prayers of Julia and Bob. How? His middle knowledge.
My mother told me that when she was pregnant with me, she spent hours every night praying that her son would be saved, would love The Lord, and would serve Him all his life. Well, look at me now. I love God. I suspect that had my mother not spent time praying that I would be saved, perhaps God would have created a different soul in her womb. One who, if he endured through similar circumstances, would not have come to Christ. Knowing my mother would pray for a son who is saved, God chose in advance to actualize a world where I was in her womb instead of some other person.
Now, although Molinism solves the problem of how God can answer prayers which involve free will creatures doing certain things, it may still be the case that free will makes answering some prayers infeasible. For example, maybe In W57, a man named Jim grows up not knowing Christ and resisting the gospel every time its presented to him. Suzan, his mother, prays for Jim to get saved every night. However, Jim never comes to Christ in his lifetime. He dies. Perhaps in W57, 3 other people get saved at the expense of Jim rejecting Christ. If God were to actualize a world where Jim finds himself in a circumstance where he is saved, maybe these 3 other souls would be lost. If circumstance S is a circumstance where God knows persons A, B, and C would freely choose to be saved, might just as well be a circumstance where persons D, E, and F are damned. If God chooses to actualize circumstance S, He brings about the salvation of persons A, B, and C, but consequently, D, E, and F are damned. If God were to refrain from actualizing circumstance S, D, E, and F would be saved, but sadly, persons A, B and C would be eternally damned. And I hold that there are most likely many, many circumstances like that. The circumstances cannot be cobbled together to ensure universal salvation because the salvic-circumstances cancel each other out in many many cases. I go into this in more detail in "What's The Point In Praying For Someone's Salvation?" So even though we can pray for the salvation of a loved one, or even universal salvation, that doesn't mean God will able to bring it about. God cannot force people to freely do something. To force someone to freely do something (e.g accept Christ) is logically impossible, for if they do it freely, they weren't forced. If they were forced, they didn't do it freely.
5: There's Unrepented Sin In Your Life
The Bible tells us that if we have sin in our life that we haven't repented of, God won't answer our prayers. The Bible says "God opposes the proud, but gives grace to the humble." (James 4:6). If you've got the sin of pride in your life, God is opposed to you. If you're vain, if you take all the credit for your accomplishments, if you think highly of yourself, God is opposed to you. In that case, you shouldn't expect Him to do anything you ask of Him.
Proverbs 28:9 says "He who turns away his ear from listening to the law, Even his prayer is an abomination." John 9:31 says "We know that God does not listen to sinners. He listens to the godly person who does his will." Proverbs 15:29 says "The LORD is far from the wicked, But He hears the prayer of the righteous." Psalm 34:15-16 says "The eyes of the LORD are on the righteous, and his ears are attentive to their cry ;but the face of the LORD is against those who do evil, to blot out their name from the earth."
If you are living in sin and won't repent of it, you can expect God to not pay attention to your prayers. Now, none of us are perfect. We all mess up from time to time. We are, as Martin Luther put it "Justified, yet simultaneously sinners". 1 John 1:7-9 even presupposes that the Christian will morally screw up from time to time. However, what I'm talking about here is purposefully clinging to sin when you know that what you're doing is wrong. You can't wallow in a sinful lifestyle and expect your prayer life to prosper. Sin is an abomination to God. Habbakuk 1:13 says that sin is so disgusting to God that He can't bear to even look upon it. If you want God to listen to you, get the filth out of your life, whatever that may be; porn, homosexual relationships, drugs, alchohol use that leads to drunkenness, or something else. Whatever it may be, get it out of your life. Otherwise, your prayers will fall on deaf ears. In fact, Proverbs 28:9 says your prayers themselves will even be considered an abomination by God!
God has reasons for why He doesn't answer our prayers. These are some of them. It's impossible to know in many cases exactly why God told us "no", but in the cases of numbers 2 and 5, introspection will tell.