ANSWER: Interestingly, John himself wondered why Jesus came to him to be baptized! All four gospels record this momentous event (Matthew 3:13 - 17, Mark 1:9 - 11, Luke 3:21 - 22 and John 1:28 - 34), with both Matthew and John writing the most details. Before we directly answer your question, however, a little background regarding the relationship of John with Jesus will prove helpful.
Scripture tells us that John knew, before he baptized Jesus, that his preaching was preparing the way for the Messiah (John 1:23). Yet, at the same time, he TWICE states that he did not know, with absolute certainty, who exactly was the Lamb of God (verses 31, 33). Even though they had a family relationship through their mothers (Luke 1:36), John lived the majority of his life in the hill country of Hebron (Luke 1:80) while the home of Jesus was more than 50 miles (80 kilometers) away in Nazareth. As such, it is likely they did not have an ongoing personal relationship with each other before The Lord was baptized.
The Holy Spirit in John, as Jesus approached him in the Jordan, convicted him that the person coming toward him was the Messiah. The sign confirming (but only to John), without a doubt, that Christ was God's Son would happen right after the baptism (John 1:33). When the Lord approached the Jordan John the Baptist stated, "I have need to be baptized by You, and You come to me?" (Matthew 3:13 - 14, HBFV).
The Bible then informs us why the Son of God needed to be baptized. Jesus answered John by stating, "You must permit it at this time; for in this manner it is fitting for us to fulfill all righteousness" (Matthew 3:15).
The Lord was not baptized, like all the others that came to John, as a sign of repentance from sin. He submitted himself to this humble act (see Philippians 2:8) because it fulfilled God's will for him. It was a visible sign that he was placing himself fully under the direction of our heavenly Father. This is confirmed by what happened next.
16. And after He was baptized, Jesus came up immediately out of the water; and behold, the heavens were opened to him, and he saw the Spirit of God descending as a dove, and coming upon Him . . ." (Matthew 3:16, see also Mark 1:10 - 11, Luke 3:22, John 1:32).
The descent of the Holy Spirit upon Jesus and God's words from heaven fulfilled several Old Testament prophecies (Psalm 2:7, Isaiah 11:2, 42:1, 21, 61:1).
Jesus was baptized in the fall of 26 A.D. when he was about thirty years old (Luke 3:23). This event is pivotal in the Bible, as it is the starting point for Christ's three and one-half year earthly ministry that will end in the spring of 30 A.D. Soon after his face-to-face meeting with John the Baptist, he was tempted by Satan for forty days and nights (Matthew 4, Luke 4).