In Bava Metzia 14b we find that the Talmudic sage Rav said that in a case where one has bought something from a thief and the property returns to  the owner, that the buyer [party number three] gets the money he paid for it from the thief and the improvement also. Rashi explain that this is a case in which the original property was already improved and the thief damaged the property. So the original owner is getting back the property with zero improvement. Tosphot explains that the case is simply that the property was empty and the buyer improved it, and so when Rav says the thief pays back the improvement, it is a simple case of his giving back the improvement, and the original owner gives back the investment to the buyer.

The idea of Tosphot is that this is not any different from a case where a person goes into someone else's field and plants it. In such a case the owner pays the investment, but not the improvement.
This all seems simple and plain. Now this is also the way the Pnei Yehoshua understands this and it seems like there is no need of any explanation.

The problem here arises when we look at Bava Kama page 95a. It looks like this entire subject in Bava Metzia is going according to the opinion of Rabbi Meir over there, and against Rabbi Yehuda and Rabbi Shimon.--which seems absurd on the face of it. Simply put, it so happens that R. Meir is the one person who holds that improvement goes back to the original owner with the stolen object--not Rabbi Yehuda or Rabbi Shimon. But if you try to explain the subject in Bava Metzia as if it was going like the halacha (law) in Bava Kama, you encounter major problems. Some of these problems were noted by the Pnei Yehoshua, but there is  a  question  that seems to me to be even more powerful that the questions the Pnei Yehoshua raised. The fact is that Shmuel is the person that argues with Rav in Bava Metzia and he says the third party --the buyer-- does not get back the improvement. If you try to explain this according to Rabbi Yehuda it makes no sense. Of course he does not get back the improvement -- because no one took it from him in the first place!
In short, the whole subject in Bava Metzia seems to be going completely like Rabbi Meir and we know from Tractate Eruvin that this is simply impossible. When there is an argument between Rabbi Meir and or Rabbi Shimon with Rabbi Yehuda the law always is like Rabbi Yehuda.

Here is a different idea on that some page.

 ב''מ יד: יש פה שלשה אנשים: נגזל,גזלן, ולוקח מן הגזלן והקרקע שנגזלה. הקרקע חוזרת לבעלים עם השבח שהשביחה הלוקח. רב אמר שהלוקח גובה מחיר הקרקע ושבחה מן הגזלן. תוספות אומרים שהדין של היורד לתוך שדה חבירו בלי רשות שמקבל היציאה שייך לפה. זה דין של רב בדף קג. ושם רב אומר ידו על התחתונה. זאת אומרת שאם השבח פחות מן היציאה, אז הנגזל משלם את היציאה. ואם היציאה פחותה, אז הוא משלם את היציאה. ועכשיו אפשר להבין כוונת התוספות פה בדף יד:. פה יש שתי אפשריות. א) השבח יותר מן היציאה. ב) השבח פחות מן היציאה. מצב הראשון הוא המצב שרב דיבר עליו. שם הנגזל משלם את היציאה, והגזלן משלם את השבח. [פה כוונת רב היא שהגזלן משלם את השבח היתר מן היציאה, היינו ההפרש. וזה שלא ככוונתו בדף קג. אולי יש פה איזו קושיא?] במצב השני שהשבח פחות, אז הגזלן אינו משלם כלום, והנגזל משלם את השבח. וזאת היא השאלה שלי. למה הגזלן אינו משלם את היציאה? אם אנחנו הולכים לפי מה שכתוב בשטר, אז הוא חייב לשלם את היציאה. אם אנחנו לא הולכים לפי מה שכתוב בשטר (אחריות לאו טעות סופר היא) אז גם השבח אינו משלם

[Looking at this essay later I am not sure why I did not write the first idea in Hebrew.  I think the reason I did not put the first paragraph into Hebrew was  I was thinking along the lines   of Tosphot that the two Gemaras pg 14 and 101 mean the same thing-that the שבח goes to the thief and then to the buyer. But later I decided that that can't be what Tosphot meant. Rather who ever did the שבח gets paid for it. And therefore the whole above essay becomes important again.