John baptized Jesus "to fulfil all righteousness" (Mt 3:15). Jesus, being sinless, has no need for baptism himself. However, his baptism follows the pattern his ministry will take. In other words, in order for Jesus to take upon himself the sins of all men, he "takes their place" in his submersion into and ascent out of the waters. Jesus' baptism is therefore a sign that he takes the place of sinners, substituting himself for them. At the beginning of his ministry, Jesus already points to the Cross, where his definitive act of substituting himself for sinners takes place.
Jesus had no sin but he demonstrated his obedience to God by being baptized. He placed himself in solidarity with sinners.
+++