Short answer
He prayed because he was not God. The Gospels show him praying to God (﷾) again and again. Luke says he withdrew into the wilderness to pray, and once "continued all night in prayer to God". In Gethsemane he fell on his face and prayed three times about the cup he was to drink. Each time he gave way: "not as I will, but as thou wilt". Hebrews says he prayed "with strong crying and tears unto him that was able to save him from death". Someone who begs another for help, and yields his will, has a God above him. Islam teaches that Jesus was a servant and prophet of God (﷾). The Qur'an records him saying that God (﷾) "enjoined on me Prayer" for as long as he lived.
Full explanation
A man of prayer
The Gospels (the four accounts of Jesus' life at the start of the New Testament) show Jesus leaving the crowds to pray alone. He prayed in the wilderness, on a mountain, and before dawn. Once he spent the whole night "in prayer to God". He prayed to God (﷾) as every prophet before him did: as one who needs God (﷾), not as one who has no need. When he was asked for the first commandment, he gave the creed of one God (﷾): "The Lord our God is one Lord". A creed is a statement of belief.
“And he withdrew himself into the wilderness, and prayed.”
“And it came to pass in those days, that he went out into a mountain to pray, and continued all night in prayer to God.”
“And in the morning, rising up a great while before day, he went out, and departed into a solitary place, and there prayed.”
“And when he had sent the multitudes away, he went up into a mountain apart to pray: and when the evening was come, he was there alone.”
“And Jesus answered him, The first of all the commandments is, Hear, O Israel; The Lord our God is one Lord:”
Gethsemane: three prayers, one answer
Gethsemane is the place outside Jerusalem where Jesus prayed on the night the Gospels say he was arrested. He fell on his face and asked his Father to let the cup pass from him. The cup is a picture for the hard trial ahead of him. He went back and prayed a second time: "if this cup may not pass away from me, except I drink it, thy will be done". Then he prayed a third time, saying the same words. He could not make the cup pass himself. He asked the One who could, and each time he accepted that One's will. A God who knows all things and can do all things has no one to beg.
“And he went a little further, and fell on his face, and prayed, saying, O my Father, if it be possible, let this cup pass from me: nevertheless not as I will, but as thou wilt.”
“He went away again the second time, and prayed, saying, O my Father, if this cup may not pass away from me, except I drink it, thy will be done.”
“And he left them, and went away again, and prayed the third time, saying the same words.”
Cries and tears to the one who could save him
The letter to the Hebrews is a book of the New Testament, and Christians hold it as Scripture. It describes his prayers as strong crying and tears offered to the one "able to save him from death". He did not save himself by his own power. He asked the One who could. Hebrews adds that he "was heard". It was the prayer of a servant, answered by his Lord.
“Who in the days of his flesh, when he had offered up prayers and supplications with strong crying and tears unto him that was able to save him from death, and was heard in that he feared;”
Two wills, and one gives way
The Qur'an says that if there were other gods beside God (﷾), there would be confusion, with each god claiming his own creation. The reasoning is simple. If two divine wills could ever disagree, one would have to give way. The one that gives way was never God. Christians say Jesus is God. Yet in Luke's account of the night he prayed about the cup, the will Jesus calls "my will" gives way to his Father's. One whose will gives way to God's (﷾) is not God.
“If there were, in the heavens and the earth, other gods besides Allah, there would have been confusion in both! but glory to Allah, the Lord of the Throne: (High is He) above what they attribute to Him!”
“No son did Allah beget, nor is there any god along with Him: (if there were many gods), behold, each god would have taken away what he had created, and some would have lorded it over others! Glory to Allah! (He is free) from the (sort of) things they attribute to Him!”
“Saying, Father, if thou be willing, remove this cup from me: nevertheless not my will, but thine, be done.”
The Christian answer: he prayed as a man
Christians answer that the eternal Son took "the form of a servant" and became fully human. On this reading he prayed in his human nature, as a true man, while remaining God (﷾). His prayers show that he was truly human, not that he was less than God (﷾). In 681 a church council added that he has two wills, divine and human. It said his human will is subject to the divine will. Christians read Gethsemane in that light.
“But made himself of no reputation, and took upon him the form of a servant, and was made in the likeness of men:”
The council confessed two natural wills and two natural operations in Christ, and taught that his human will follows, and is subject to, his divine and all-powerful will.
Who was praying?
A nature does not pray; a person does. In 451 the Council of Chalcedon, a church council, defined Christ as one person, "not parted or divided into two persons". So on the creed's own terms, the one who prayed was God the Son. That means God the Son begged for what he could not grant himself, and gave up his own will. An all-knowing, all-powerful God (﷾) cannot do this. If only the man prayed, there are two persons in Christ, and the same council rejected that. The Gospels never sort his words in this way. They show one man praying to his God.
The council confessed one and the same Christ in two natures, divine and human, and declared him "not parted or divided into two persons, but one and the same Son".
“Saying, Father, if thou be willing, remove this cup from me: nevertheless not my will, but thine, be done.”
What the Qur'an says
The Qur'an records Jesus saying that he is a servant of Allah (﷾) whom God (﷾) made a prophet. It says God (﷾) commanded him to pray for as long as he lived. It also says Christ never disdained to serve and worship Allah (﷾).
“He said: "I am indeed a servant of Allah: He hath given me revelation and made me a prophet;”
“"And He hath made me blessed wheresoever I be, and hath enjoined on me Prayer and Charity as long as I live;”
“Christ disdaineth nor to serve and worship Allah, nor do the angels, those nearest (to Allah): those who disdain His worship and are arrogant,-He will gather them all together unto Himself to (answer).”
Verse by verse
Luke 22:42 — Gospel of Luke, chapter 22, verse 42
“Saying, Father, if thou be willing, remove this cup from me: nevertheless not my will, but thine, be done.”
Cited for
Only the human will of Christ gave way. His divine will was untouched.
The response
A will belongs to someone, and the creed says Christ is one person, "not parted or divided into two persons". The church's later answer came at the Third Council of Constantinople in 681. It said the one Son has two wills, and his human will yielded to the divine will, which is also his own. But Jesus did not say "not my human will but my divine will". He said "not my will, but thine". The will he gave way to, he called his Father's, not his own. Luke's account shows no such division. It shows one man praying to his God.
Where it lands — The two-natures answer does not remove the problem: the one who prayed and gave way is not God.
Matthew 26:39 — Gospel of Matthew, chapter 26, verse 39
“And he went a little further, and fell on his face, and prayed, saying, O my Father, if it be possible, let this cup pass from me: nevertheless not as I will, but as thou wilt.”
Cited for
Jesus prayed to set an example of prayer for his followers.
The response
An example does not need three prayers about the same cup. It does not need "strong crying and tears" to the one "able to save him from death". These were real requests made to a God above him.
Where it lands — His prayers were the prayers of a servant to his Lord, not a demonstration.
Perspectives
Mainstream Christian
Jesus prayed as a true man. The eternal Son took on a full human nature. In that nature he prayed, depended on the Father and submitted to His will. He left his followers an example.
Philippians 2:7 says he took the form of a servant and was made in the likeness of men. Christians place his prayers in that human life.
Rebuttal
The verse says he took a servant's form, but a nature does not pray; a person does. Chalcedon says Christ is one person, so the one who begged was God the Son. A God who can do all things has no one to beg.
The Church teaches that Christ is one person in two natures, so he could pray as man while being God.
Rebuttal
That is what the Church teaches, but the same council says Christ is "not parted or divided into two persons". So the one who prayed was God the Son, begging and giving up his will. An all-powerful God (﷾) cannot do this.
The Church teaches that Christ has two wills, divine and human, with the human will subject to the divine. Christians read Gethsemane as that submission.
Rebuttal
A will belongs to someone, and the creed says Christ is one person. Jesus did not say "not my human will but my divine will". He said "not my will, but thine", and called the will he gave way to his Father's.
The Islamic perspective
Jesus prayed because he was a servant and prophet of God (﷾). His prayers show a God above him, whom he begged, obeyed and worshipped.
Jesus often withdrew to pray, and once continued all night in prayer to God (﷾). He gave the creed of one God (﷾) as the first commandment.
In Gethsemane he fell on his face and prayed three times about the cup. First he asked that it pass from him.
He set his own will aside for the will of another: "not my will, but thine, be done".
Suppose two divine wills could disagree. Then one would have to give way, and the one that gives way is not God.
Hebrews says he prayed with strong crying and tears to the one able to save him from death.
The creed makes Christ one person. So the two-natures answer leaves God the Son praying to God (﷾) and yielding his will.
The Qur'an teaches that Jesus was a servant of Allah (﷾), commanded to pray as long as he lived.