The question "why" is open to some speculation when the scriptures are silent on certain reasons, but it helps to be able to empathize with the events of the time, and to walk with them in their shoes with as much information as we can pull together. The two main reasons offered by the commentaries center around sorrow for John's death, and avoiding a meeting with Herod which might have resulted in the wrong time and place for Jesus' own death.
The parallel accounts of this are Mark 6:30-44; Luke 9:10-17; and John 6:1-24.
Ellicott's Commentary at Matt. 14:13,
"(13) When Jesus heard of it.—We may, I think reverently trace as the motives of this withdrawal, (1) the strong personal emotion which the death of one whom Jesus had known and loved could not fail to cause, and (2) the wish to avoid being the centre of the popular excitement which the death of John was likely to cause, and which we know, as a matter of fact (Jos. Ant. xviii. 5, § 2), was so strong that men looked on all the subsequent troubles of Antipas and his wife as a retributive judgment for it. This was, indeed, sufficiently shown by the eagerness with which the people followed Him into His retirement. Two other circumstances, named by the other Evangelists, tended to increase the crowd that thronged around Him. (1) The Twelve had just returned from their missionary circuit (Mark 6:30-31; Luke 9:10), and it was, indeed, partly to give them, too, an interval of repose that He thus withdrew from His public work; and (2) the Passover was coming on (John 6:4), and all the roads of Galilee were thronged with companies of pilgrims hastening to keep the feast at Jerusalem." Source: Biblehub
Jamieson-Faussett-Brown on Mark 6:30-44,
"30. And the apostles gathered themselves together—probably at Capernaum, on returning from their mission (Mr 6:7-13).
and told him all things, both what they had done, and what they had taught—Observe the various reasons He had for crossing to the other side. First, Matthew (Mt 14:13) says, that "when Jesus heard" of the murder of His faithful forerunner—from those attached disciples of his who had taken up his body and laid it in a sepulchre (see on Mr 6:29)—"He departed by ship into a desert place apart"; either to avoid some apprehended consequences to Himself, arising from the Baptist's death (Mt 10:23), or more probably to be able to indulge in those feelings which that affecting event had doubtless awakened, and to which the bustle of the multitude around Him was very unfavorable. Next, since He must have heard the report of the Twelve with the deepest interest, and probably with something of the emotion which He experienced on the return of the Seventy (see on Lu 10:17-22), He sought privacy for undisturbed reflection on this begun preaching and progress of His kingdom. Once more, He was wearied with the multitude of "comers and goers"—depriving Him even of leisure enough to take His food—and wanted rest: "Come ye yourselves apart into a desert place, and rest a while," &c. Under the combined influence of all these considerations, our Lord sought this change." Source: Biblehub
Ellicott's reference to Josephus' Antiquities XVIII, 5.2 offers a few insights on the Jews' reaction to John's death.
"2. Now some of the Jews thought that the destruction of Herod's army came from God, and that very justly, as a punishment of what he did against John, that was called the Baptist: for Herod slew him, who was a good man, and commanded the Jews to exercise virtue, both as to righteousness towards one another, and piety towards God, and so to come to baptism; for that the washing [with water] would be acceptable to him, if they made use of it, not in order to the putting away [or the remission] of some sins [only], but for the purification of the body; supposing still that the soul was thoroughly purified beforehand by righteousness. Now when [many] others came in crowds about him, for they were very greatly moved [or pleased] by hearing his words, Herod, who feared lest the great influence John had over the people might put it into his power and inclination to raise a rebellion, (for they seemed ready to do any thing he should advise,) thought it best, by putting him to death, to prevent any mischief he might cause, and not bring himself into difficulties, by sparing a man who might make him repent of it when it would be too late. Accordingly he was sent a prisoner, out of Herod's suspicious temper, to Macherus, the castle I before mentioned, and was there put to death. Now the Jews had an opinion that the destruction of this army was sent as a punishment upon Herod, and a mark of God's displeasure to him." Source: Josephus Antiquities
So, Herod's guilt over John's death, and his fear that Jesus was John risen from the dead (Matt. 14:2) motivated him to seek out Jesus. And, such a meeting at that time might have resulted in another death sentence which would not have been the one prophesied for the Lamb slain from the foundation of the world (Psa. 22:16, 18; 69:21; Isa. 50:6; 52:14; 53:7; Zech. 11:12; 12:10; Rev. 13:8)
But, we should remember that John was also Jesus' cousin (kin), a family member (1), a brother in the work, and a precious soul to Christ.
"Truly, I say to you, among those born of women there has risen no one greater than John the Baptist;..." (Matt. 11:11, RSV)
Jesus would not be concerned over John's soul as He knew where John was, but the violence and method of John's death is still a horrible event that causes pain and sorrow in our hearts even today.
1) Mary was a cousin of kinswoman to Elizabeth - See Apologetics Press, "How Were Mary and Elizabeth Related" here