The Bible canon does not contain the episode of Mary, Jesus and the palm tree, it is included in the apocrypha. However, the Qur'an does contain this story.
Then she conceived him; and withdrew with him to a remote place. And the throes of childbirth drove her to the trunk of a palm-tree. She said: Oh, would that I had died before this, and had been a thing quite forgotten!
So a voice came to her from beneath her: Grieve not, surely thy Lord has provided a stream beneath thee. And shake towards thee the trunk of the palm-tree, it will drop on thee fresh ripe dates. So eat and drink and cool the eye. Then if thou seest any mortal, say: Surely I have vowed a fast to the Beneficent, so I will not speak to any man to-day.
Gospel of Pseudo-Mathew
Quranic verse 19:22-26 is a clear parallel of the account found in the Gospel of Pseudo-Matthew.
And it came to pass on the third day of their journey, while they were walking, that the blessed Mary was fatigued by the excessive heat of the sun in the desert; and seeing a palm tree, she said to Joseph: Let me rest a little under the shade of this tree. Joseph therefore made haste, and led her to the palm, and made her come down from her beast. And as the blessed Mary was sitting there, she looked up to the foliage of the palm, and saw it full of fruit, and said to Joseph: I wish it were possible to get some of the fruit of this palm. And Joseph said to her: I wonder that thou sayest this, when thou seest how high the palm tree is; and that thou thinkest of eating of its fruit. I am thinking more of the want of water, because the skins are now empty, and we have none wherewith to refresh ourselves and our cattle. Then the child Jesus, with a joyful countenance, reposing in the bosom of His mother, said to the palm: O tree, bend thy branches, and refresh my mother with thy fruit. And immediately at these words the palm bent its top down to the very feet of the blessed Mary; and they gathered from it fruit, with which they were all refreshed. And after they had gathered all its fruit, it remained bent down, waiting the order to rise from Him who bad commanded it to stoop. Then Jesus said to it: Raise thyself, O palm tree, and be strong, and be the companion of my trees, which are in the paradise of my Father; and open from thy roots a vein of water which has been hid in the earth, and let the waters flow, so that we may be satisfied from thee. And it rose up immediately, and at its root there began to come forth a spring of water exceedingly clear and cool and sparkling. And when they saw the spring of water, they rejoiced with great joy, and were satisfied, themselves and all their cattle and their beasts. Wherefore they gave thanks to God.”
The dating of this apocrypha is contentious. Most scholars date it to the fourth or fifth century, although some date it later to the eighth or ninth century. However, the balance of probability suggests that it pre-dates Islam. This is due to its reference in the ‘Decretum Gelasianum De Libris Recipiendis Et Non Recipiendis’ as ‘the book of the nativity of the saviour and of Mary or the midwife’.
(Note: Apocrypha are known by various names, particularly in translations.)
The Decretum is said to have been issued by Pope Gelasius I (492-496 AD) in 494 AD, although some scholars claim it was wrongly attributed to Gelasius I and believe it to have actually been written in the sixth century.
Here are some evidence for the dating of the apocrypha:
Pseudo-Matthew, Gospel of
, a late Latin infancy gospel of 8th or 9th century. Our earliest MSS are of the 11th century. When certain infancy gospels had been condemned by Popes Damasus, Innocent I, and the Gelasian Decree popular interest seems to have motivated the writing of Pseudo-Matthew. It is substantially a rewrite, with additions, omissions, changes of the Protoevangelium of James and the Gospel of Thomas. It seems also to have aimed at the veneration of Mary as Queen of Virgins. It had great influence on medieval literature and art.
When asking about sources or origins of the Nativity, we are well advised to look with one eye to the Bible (the Infancy Narrations in Luke and Matthew), and with the other eye, to the so-called apocryphal writings. Among them are four I would like to mention: the Pseudo-Gospel of James (150-2--), where the midwife and her friend are mentioned; the Arabic Infancy Gospel (500); the Book about the Infancy of the Savior (500-800); and the Pseudo-Gospel of Matthew (550-700).
Gospel of St. Matthew
: This is a Latin composition of the fourth or fifth century. It pretends to have been written by St. Matthew and translated by St. Jerome. Pseudo-Matthew is in large part parallel to the "Protoevangelium Jacobi", being based on the latter or its sources. It differs in some particulars always in the direction of the more marvellous. Some of its data have replaced in popular belief parallel ones of the older pseudograph. Such is the age of fourteen in which Mary was betrothed to Joseph. A narrative of the flight into Egypt is adorned with poetic wonders. The dragons, lions, and other wild beasts of the desert adore the infant Jesus. At His word the palm-trees bow their heads that the Holy Family may pluck their fruit. The idols of Egypt are shattered when the Divine Child enters the land. The "Gospel of the Nativity of Mary" is a recast of the Pseudo-Matthew, but reaches only to the birth of Jesus. It is extant in a Latin manuscript of the tenth century.
Tisdall: The Pseudo-Matthew (otherwise called Hist. Nativ. Mariae) "may belong to the fifth century." (Cowper, p. 27; cf. Introd., p. liv.)
Jacques Hervieux writes in "The New Testament Apocrypha", published by Hawthorn Books, page 18: "About the sixth century there appeared in Latin a certain book on the birth of the Blessed Mary and of the Savior's infancy. An introductory letter presented this new work as a "supplement" to the Gospel of St. Matthew, translated personally by St. Jerome the great fourth century exegete." "The New Testament Apocrypha", Hawthorn Books. 
The Gospel of Pseudo-Matthew. The "Protoevangelium Jacobi" has its Latin counterpart in the Gospel of Pseudo-Matthew, entitled Liber de Ortu Beatae Mariae et Infantia Salvatoris, the contents of which are much the same as that of the "Protoevangelium," plus the subject matter of the "Gospel of Thomas." It is a compilation of the fifth century.
The greater number of the authorities on the subject, however, seem to agree in assigning to the first four centuries of the Christian era, the following five books: 1. The Protevangelium of James; 2. The Gospel of Pseudo-Matthew; 4. The History of Joseph the Carpenter; 5. The Gospel of Thomas; 9. The Gospel of Nicodemus.
Leto in Greek mythology
Suleiman Mourad has traced the development of this story in the Qur'an and Gospel of Pseudo-Matthew through Greek and Latin literature. He writes:
All the various Hellenistic and Latin variants of the original myth of Leto giving birth to Apollo by a palm tree reflect the borrowing and adaptation by groups who reshaped it for their own objectives and needs. Appropriations of ancient myths were common in the ancient world, and the early Christians were no exception. The palm-tree story that found its way to sura Maryam is a reworking of Leto's labor. It is about a distressed pregnant woman (Leto/Mary) who seeks an isolated place (Delos/a remote spot), sits by the trunk of a palm tree next to a stream (Inopos/a brook), and delivers a holy child (Apollo/Jesus).
It is nevertheless unlikely that the myth of Leto was the direct source for sura Maryam. As was aforementioned, the concise version found in the latter has two parts: Mary's labor and delivery, and the miracle. We might therefore suspect that there was a stage when Leto's myth was borrowed and applied to Mary.
The parallel between the Qur'an and the Gospel of Pseudo-Matthew suggests a non-divine source for the Qur'an. This story, in which Jesus was still in the womb during the flight to Egypt, is clearly at odds with the canonical gospels which suggest that Jesus was born in Bethlehem (Matthew 2:1,5-6,8,16; Luke 2:4,15; John 7:42) and the flight to Egypt occurred only after his birth at Bethlehem.
And when they were departed, behold, the angel of the Lord appeareth to Joseph in a dream, saying, Arise, and take the young child and his mother, and flee into Egypt, and be thou there until I bring thee word: for Herod will seek the young child to destroy him. When he arose, he took the young child and his mother by night, and departed into Egypt.
Christians believe that Jesus was prophesized to be born at Bethlehem (Micah 5:2). It looks like Muhammad bin Abdallah never read the Old Testament.