The reason behind this strange quote is given nicely in the Introduction to Autobiographical Writings. Hesse is writing a "fictional autobiography", extrapolating how his future life would be from the events of the present and his character. Theodore Ziolkowski, the writer of the Introduction explains:
while Hesse's novels emerge and are shaped from autobiographical
reality, a reverse movement is simultaneously at play: for his
autobiographical writings often tend to blend back into fiction... The
most startling example of this playful bending of reality occurs at
the end of "Life Story Briefly Told," where Hesse, after
recapitulating the events of his life up to the time of writing
(1925), speculates on its course in the future. It would be
inevitable, he surmises, that a man of his noncomformist disposition
should sooner or later come into conflict with the law. Late in his
life, presumably, he would be arrested -- say, for the seduction of a
young girl by means of magic.
So in real life Hesse was not, of course, ever arrested for "seduction by magic". It is just how he imagined how his life might end up 22 years in the future. As Ziolkowski notes:
Whether Hesse is writing "fiction" or "autobiography," he almost
invariably ends up in what he has called the "timeless realm of the
spirit," which is located just outside time and space