When John the Baptist was in prison, he begins to have some doubts about the identity of Jesus. We read John ... "calling two of his disciples to him, sent them to Jesus, saying, 'Are You the Coming One, or do we look for another?'" Luke 7:19
It can be said that even the prophet John the Baptist had doubts. Why this uncertainty, when his divine mission was certain, and God gave evidence that Jesus was His son? John being in prison could have been part of the reason, because difficulty can cause one to have doubt.
It could be that the course of Jesus' ministry led to some uncertainty, if John had limited understanding of the course Jesus' ministry would take.
The fact John asked this of Jesus shows that he believed Jesus was sent from God, and John would trust his response, even if he wasn't the anticipated "Christ," because obviously God was with Jesus.
It may be that he was familiar with a teaching that there would be two messiahs, and maybe in light of the course that Jesus' ministry was taking, he might have wondered if that two-messiah-view had some validity to it. The two-messiah-view is the view that there would be a suffering messiah, being "Messiah Ben Joseph," and a conquering messiah, "Messiah Ben David." We can't know if that added to John's uncertainty or not. Difficulty in life can cause us to sometimes question things of which we were once convinced.
John needed reassurance that Jesus was the Christ. Jesus' response was not one of rebuke, and Jesus had nothing critical to say about John. Jesus gave demonstration through miracles to John's disciples that he was The Christ. There is something to learn from this about doubt and asking God for reassurance.
------
Then the disciples of John reported to him concerning all these things. And John, calling two of his disciples to him, sent them to Jesus, saying, "Are You the Coming One, or do we look for another?"
When the men had come to Him, they said, "John the Baptist has sent us to You, saying, 'Are You the Coming One, or do we look for another?'" And that very hour He cured many of infirmities, afflictions, and evil spirits; and to many blind He gave sight. Jesus answered and said to them, "Go and tell John the things you have seen and heard: that the blind see, the lame walk, the lepers are cleansed, the deaf hear, the dead are raised, the poor have the gospel preached to them. And blessed is he who is not offended because of Me."
When the messengers of John had departed, He began to speak to the multitudes concerning John: "What did you go out into the wilderness to see? A reed shaken by the wind? But what did you go out to see? A man clothed in soft garments? Indeed those who are gorgeously appareled and live in luxury are in kings' courts. But what did you go out to see? A prophet? Yes, I say to you, and more than a prophet. This is he of whom it is written: 'Behold, I send My messenger before Your face, who will prepare Your way before You.' For I say to you, among those born of women there is not a greater prophet than John the Baptist; but he who is least in the kingdom of God is greater than he." Luke 7:18-28