Answer: The situation you are referring to in the Bible is when the disciples tried to cast out a demon from a man's son but could not. The man told Jesus what happened.
"Lord, have mercy on my son, for he is insane and suffers miserably; for he often falls into the fire, and often into the water. And I brought him to Your disciples, but they were not able to heal him (cast out the demon)."
Then Jesus answered and said, "O faithless and perverse generation, how long shall I be with you? How long shall I bear with you in your unbelief? Bring him here to Me" (Matthew 17:15 - 17, HBFV).
Jesus, of course, could and did cast the demon out of the man's son. The son was immediately healed. Perplexed as to why they could not help the man, the disciples asked Christ why they could not expel the evil spirit. His response was "It was because you do not have enough faith" (Matthew 17:20). He also added, however, that it required fasting and prayer to remove the type of evil presence they had encountered.
Interestingly, just before Matthew's account of the disciples' inability to expel a disobedient spirit, Jesus had sent them on a "gospel training mission" to some cities. The Lord, before they left, gave them the authority to heal the sick, raise the dead and cast out demons wherever they went (Matthew 10:5 - 15).
A serious warning
What is the warning from the above scriptures? Just because a person believes in Jesus or uses his name, does not mean they have the faith and authority from God for casting out evil spirits!
Driving away evil spirits is serious business and not to be taken lightly. Anyone taking on themselves the driving out of these spirits had better be well grounded in the scriptures and have an ample portion of God's Holy Spirit!
Those who wrongly assume they have the authority necessary to cast out devils can suffer some very real painful consequences, as seven sons mentioned in the New Testament found out. They tried to claim power over the disobedient spirit by saying 'I command you in the name of Jesus, whom Paul preaches.' (Acts 19:13). The spirit was not amused. It caused the man it possessed to attack the men and wound them (verse 16)!
Those in Acts 19 who were claiming the ability to cast our demons were sons of a Levite chief priest. Because of this, they must have thought of themselves as being pretty important and powerful, certainly powerful enough to simply assume they could use the name (authority) of Jesus Christ (after only hearing of Him through the apostle Paul) to command obedience from fallen angels.
There was, however, one problem. These men believed all they needed to do was use Jesus' name, kind of like a magician who says some "magic words" before a trick, and then what they wanted to happen would occur. The difficulty was the evil spirit(s) they were trying to cast out knew the true power it took to force them to leave and knew these men were pretending that they had it!
Ironically, the men pretending they represented God were in reality deceived, while those whose existence was based entirely on deception (demons) knew the truth!
Those Christians and others who saw or heard of what happened quickly learned not to take the name and authority of Jesus Christ lightly! They knew not to assume they had God's authority to do whatever they pleased whenever they wanted. If the Lord has not ordained you to use His name to cast out demons, do not think you can simply conjure up some faith and do it anyway.