In Luke 7 it says that John the Baptist asked if Jesus was the One they were waiting for, but back in Chapter 3 when John baptizes Jesus, it says that the heavens opened, the Holy Spirit descended like a dove and the Father spoke. Wouldn't John have seen and heard this and therefore known who Jesus was?
In Jewish teaching of Jesus' day, there came to be a misconception concerning the Messiah. Jewish teachers taught that there must be two Messiahs since the prophecies concerning the Messiah seemed to split into two different types.
First, there were prophecies that foretold a suffering, dying Prophet who would be led to the slaughter for the sake of Israel. Secondly, there were other prophecies that foretold a conquering Christ who would rule the world in glory. Since the teachers of Israel couldn't reconcile these two (seemingly) contradictory prophecies, they solved the dilemma by teaching there would be two Messiahs: a Prophet who would come to die for the sins of Israel and a Christ who would come to conquer Israel’s enemies and rule over the world in peace.
We can see this teaching reflected in a passage from John:
John 1:19 This is the testimony of John, when the Jews sent to him priests and Levites from Jerusalem to ask him, “Who are you?”
John 1:20 And he confessed and did not deny, but confessed, “I am not the Christ.”
John 1:21 They asked him, “What then? Are you Elijah?” And he said, “I am not.” “Are you the Prophet?” And he answered, “No.”
John 1:22 Then they said to him, “Who are you, so that we may give an answer to those who sent us? What do you say about yourself?”
Notice the priests asked John the Baptist if he was one of three people: Elijah, the Prophet or the Christ? Their questions reflect the teaching of their day concerning the Messiah. Apparently, John the Baptist shared this same expectation, which explains his actions in Luke 7.
Therefore, John the Baptist likely sent his disciples to question Jesus because of his confusion over the Jewish teaching of two Messiahs. John knew Jesus to be the Messiah, the Lamb of God as he declared in John 1 and witnessed in Luke 3, but he probably assumed Jesus was only the suffering Prophet (i.e., a "lamb" led to slaughter). Therefore, John the Baptist also expected a second Messiah to eventually come.
Then at some point, John the Baptist began to understand that Jesus was both the Prophet and the Christ. Therefore, John's question in Luke 7 was an inquiry as to whether Jesus was also the conquering Christ that John was still expecting. Jesus' response to John’s question made reference to miracles found in prophecies of Isaiah that were associated with the conquering Christ, so it appears Jesus was answering John's question in the affirmative by pointing to these miracles as proof that He was the expected Christ.
So, John the Baptist did know that Jesus was the Son of God but he was confused by wrong teaching to think a second Messiah would follow Jesus. Once he realized that there would be only one Messiah, he asked Jesus to confirm His identity as the Expected One, the Christ.