Herod did this because he respected/feared John, because he knew that he was a righteous and holy man. The king did not know what he should do, but he liked to listen to him.