R Ben Zion Sobel wrote about this, quoting from the sefer Chayim Sheyaish Bahem - it is a more incredible story I would have expected when reading your question !
In a nutshell the Chatam Sofer was asked if the remains of R Banet could be moved and saw him in a dream asking to delay the move as a tikun for a mistake he made (other version: he saw him after 6 months asking to now allow the move). The mistake was either a shidduch he broke or a shidduch he allowed to be broken.
On the thirteenth of Menachem Av, 5589, Rabbi Mordechai Banet ztvk"l,
the Chief Rabbi of Nikohlsburgh, passed away. Since it was during the
summer months, he was at the baths in Karlebad when he died, and he
was buried in the town of Lichtenshtatt, which was nearby. When the
community of Nikohlsburgh heard of the tragedy which had befallen
them, they insisted that their great Rabbi be moved to their town
immediately, to be buried in honor in the grave of his ancestors.
However, the community of Lichtenshtatt argued that they had been
privileged to receive the Holy Rabbi's body and it should remain by
them. The dispute was brought before the greatest Rabbis of the
generation, including the Chasam Sofer, who said that it would be
permissible to move the grave, but did not rule decisively what to do.
About six months later, the Chasam Sofer dealt with the issue again
and this time he wrote to the Judges of Nikohlsburgh that now he had
definitely decided that they should move their Rabbi back to their
town and bury him there. That is exactly what they did and he was
buried there with honors on the twelfth of Adar, 5590.
This is the version that is recorded in the book Chut Hameshulash
where it is explained that Rabbi Banet came to the Chasam Sofer in a
dream and asked him to allow them to move his body to Nikohlsburgh. He
revealed that when he was a bachur (an unmarried boy) he was engaged
to the daughter of the Rabbi of Lichtenshtatt and he broke the
shidduch, causing shame to the family of his betrothed. Therefore, he
was punished that for half a year he would have to lie in their
cemetery, far from his home town and from the graves of his ancestors.
However, his penalty was over now and therefore he requested that the
Chasam Sofer see to it that he be returned home where he belonged.
However, the author of the book Pe'er Mordechai, who wrote the
biography of Rabbi Mordechai Banet, argues that the Rabbi never broke
a shidduch in his life. He maintains that there is a mistake in the
way the story is written in the Chut Hameshulash and brings another
version from the son of the Chasam Sofer who heard it from his father.
He told that even the first time the Chasam Sofer dealt with the
question, he wrote that they are obligated to return the body to
Nikohlsburgh. However, before he could send his decision away, he fell
asleep and Rabbi Banet came to him in a dream and asked him to delay
his ruling for a while. He explained that he is being punished and
must be buried in Lichtenshtatt for half a year because he once gave
someone permission to break a shidduch. The Rabbi stressed that
"although my decision was correct according to the Torah,
nevertheless, since people's honor is a very serious matter and I
caused pain and embarrassment to the girl and her family, therefore I
am being punished!" In order to prove that his words were true, Rabbi
Banet told the Chasam Sofer that they can check and see that the
betrothed girl is buried right next to the grave where he is lying
now. The Chasam Sofer did so and found his words to be true. Therefore
he waited six months before having the Rabbi's body returned home.
We must learn from this how careful we must be never to cause pain or
embarrassment to anyone, even if he or she deserves it. Then we will
be truly happy in this world and in the World-to-Come.
The story is told elsewhere incl. here quoting the sefer Siach Nechamah by Rav Chaim Kanievsky, page 192.
As to the halachic permissibility of the re-interment, dinonline notes here it is permissible if the person is being relocated to the Land of Israel, or to the family burial plot (kever avos) (but see Igrot Moshe YD 3:153 who writes that decisions of relocation the grave can only be taken by the children of the deceased, and not by the general Jewish community).
The Sridei Eish writes (vol. 2, no. 100) the highest halachic authorities gave their permission to move R Banet's remains
The removal of bones from one gravesite to another … is a matter that
our rabbis and decisors in all generations have treated with great
severity, for we find that Chazal were very insistent on the proper
respect to be paid to the dead…. And therefore we observe that time
after time when a question concerning the disinterment of bones came
before the great masters, they would apply themselves to this halachah
with great gravity and seriousness, and they would preoccupy
themselves in the clarification and meticulous examination of all
possibilities, and they would not rush to permit even under
circumstances where the basis for leniency was clear and obvious. It
is well known how the gedolei hador were filled with fear and
trepidation when they had to decide whether to permit the disinterment
of the pure body of the Gaon Rabbi Mordechai Benet from Lichtenstaut
For further analysis, you could search for the the tshuva from the Seridei Eish or look for the relevant tshuva from the Hatam Sofer. See for instance article here and its footnotes, particularly #2, 9, 32, 37 and 42 who refer to relevant tshuvot from the Hatam Sofer.