The story is found in the Apocryphal Arabic Gospel of the Infancy of the Saviour:
(23) And turning away from this place, they came to a desert; and hearing that it was infested by robbers, Joseph and the Lady Mary resolved to cross this region by night. But as they go along, behold, they see two robbers lying in the way, and along with them a great number of robbers, who were their associates, sleeping. Now those two robbers, into whose hands they had fallen, were Titus and Dumachus. Titus therefore said to Dumachus: I beseech you to let these persons go freely, and so that our comrades may not see them. And as Dumachus refused, Titus said to him again: Take to yourself forty drachmas from me, and hold this as a pledge. At the same time he held out to him the belt which he had about his waist, to keep him from opening his mouth or speaking. And the Lady Mary, seeing that the robber had done them a kindness, said to him: The Lord God will sustain you by His right hand, and will grant you remission of your sins. And the Lord Jesus answered, and said to His mother: Thirty years hence, O my mother, the Jews will crucify me at Jerusalem, and these two robbers will be raised upon the cross along with me, Titus on my right hand and Dumachus on my left; and after that day Titus shall go before me into Paradise. And she said: God keep this from you, my son. And they went thence towards a city of idols, which, as they came near it, was changed into sand-hills.
There are also variations that make the Penitent Thief the young son of the leader of a band of thieves. Here is one other variation on the tale, which makes him a little spider. Here's a quote:
So, the soldiers passed on and left the Holy Family in peace — all because a little spider had spun its web across the entrance to the cave.
Barclay then writes: “And that, so they say, is why to this day we put tinsel on our Christmas trees, for the glittering tinsel streamers stand for the spider’s web, white with hoarfrost stretched across the entrance of the cave in which the Holy Family stopped and found shelter on the way to Egypt.
“It is a lovely story, and this much, at least, is true: No gift that Jesus receives is ever forgotten.”
All of this is considered apocrypha, so we do not need to believe that it actually happened and some of these stories can have theological problems, so it's best to be cautious, but the core of the story was not made up by the priest, if that is what you are asking.