“Go away. The girl is not dead but asleep.” (Matthew 9:24)

Here is the situation:
While he was saying this, a synagogue leader came and knelt before him and said, “My daughter has just died. But come and put your hand on her, and she will live.” (Matt. 9:18-19)

When Jesus entered the synagogue leader’s house and saw the noisy crowd and people playing pipes, he said, “Go away. The girl is not dead but asleep.” But they laughed at him. After the crowd had been put outside, he went in and took the girl by the hand, and she got up.
(Matt. 9:23-25)

Why did Jesus heal the girl?

And why didn't Jesus just heal everyone?

The healing of the girl was not Jesus’ mission. If it was, Jesus would have set up hospitals. He would have become a doctor or mass healer and had everyone line up so he could touch and heal everyone.

Rather, Jesus spent most of his time preaching. And his healings were done selectively at critical moments in his ministry.

As for the premise that Jesus was just having mercy on people - this is not necessarily wrong but it is not complete. If Jesus' purpose of healing this girl and a few others were strictly due to mercy, why didn't he heal everyone who was sick? Why did he focus on healing this daughter of a synagogue leader? Did he have more mercy on this girl than on others?

This element of selective mercy poses a challenge to the assumption of many that Jesus' purpose is about healing people's bodies. This proposition has actually been taken advantage of by some to attract followers by virtue of promising to heal everyone via Jesus.

But Jesus predicted this and disavowed this focus on miracles:
“Many will say to me on that day, ‘Lord Lord, did we not prophesy in your name and in your name drive out demons and perform many miracles?" Then I will tell them plainly, ‘I never knew you. Away from me, you evildoers!" (Matthew 7:22-23)
This relates to motive. If someone is trying to perform miracles by using Jesus for their own personal prestige, that is condemned by Jesus.

So why didn't Jesus heal everyone? Certainly, his healing abilities had no restrictions. He could have healed everyone. Why did Jesus leave so many unhealed?

First, because suffering is part of our temporary physical experience, aimed to teach us and provide consequences for our previous activities.

And second, because Jesus and God had another purpose in mind:

His healings brought attention to his teachings.

Today there are many ways to broadcast information to the masses, including television, radio and the internet. These mediums did not exist during Jesus' time. During Jesus' time, word of mouth was the central means of broadcasting.

This event illustrated that Jesus and the Supreme Being utilized this to help spread Jesus' teachings by attracting people - even into the future as we are today:
News of this spread through all that region. (Matt. 9:26)
This indicates that his healings brought Jesus attention from the masses. This attention brought large crowds to his lectures, where he presented his teachings.

And what was the essence of his teachings? When Jesus was asked what the most important commandment was, he answered:
"Love the Lord your God with all your heart and with all your soul and with all your mind and with all your strength. This is the more important commandment." (Mark 22:27-28)