Now when Jesus had heard that John was cast into prison, he departed into Galilee; Matthew 4:12
Look back now to the events immediately preceding John's death. What was Jesus doing before John was arrested? He had been fasting in the wilderness, preparing to begin His earthly ministry. And, just before that? He had been with John Baptist, in the water, being baptized. Don't be surprised at that. He was getting ready, for the time was at hand. Right on God's time John was beheaded, and Jesus was seeking the fulfillment of His calling. One did not trample the other. One's work did not clash with the other. When one descended from the job, the other ascended to the role.
This is much like Moses and Joshua. Moses laid down and died. Joshua rose up and led the nation, just as God willed it to happen. Here likewise, Jesus was prepared for the ministry while John was being arrested and executed. The time was at hand.
The people who sat in darkness saw great light; and to them who sat in the region and shadow of death, light is sprung up. Matthew 4:16