Why did John the Baptist question the identity of Jesus? Clearly John was a prophet and he dedicated his life to God. God revealed to him that Jesus was the Messiah.

In Matthew 3:13-17 he baptized Jesus, and proclaimed that he is The One in John 1:29


  The next day John saw Jesus coming toward him and said, "Look, the
  Lamb of God, who takes away the sin of the world!


When John was arrested suddenly he doubts Jesus as Messiah. In Matthew 11:2-11


  "Are you really the Messiah we've been waiting for, or should we keep
  looking for someone else?"


This doesn't make sense. How should I understand it?
In the beginning of John's mission, he seemed to think that God was coming in wrath to judge the wicked:

When he saw many of the Pharisees and Sadducees coming to his baptism, he said to them, &quot;You brood of vipers! Who warned you to flee from the coming wrath? ... Even now the ax lies at the root of the trees. Therefore every tree that does not bear good fruit will be cut down and thrown into the fire. ... His winnowing fan is in his hand. He will clear his threshing floor and gather his wheat into his barn, but the chaff he will burn with unquenchable fire.&quot;

(Matthew 3:7, 10, 12)
Jesus, although he could use hot words, did not seem to be the sort of Messiah that John was expecting. Thus, perhaps John doubted when Jesus was not who he thought the Messiah would be; but when he saw the sorts of signs Jesus worked, he had to ask. Jesus reminded John that what he did was what the Messiah would do, and he seems to have warned John that Jesus might not fulfill his expectations, but that did not mean that John should disbelieve:

&quot;Go and tell John what you hear and see: the blind regain their sight [Isaiah 29:18b, 35:5a], the lame walk, lepers are cleansed, the deaf hear [Isaiah 29:18a, 35:5b], the dead are raised [Isaiah 26:19], and the poor have the good news proclaimed to them [Isaiah 61:1].
And blessed is the one who takes no offense at me.&quot;