In an instance in which an object is found prior to forfeiture by despair ( Ye'ush) the finder is obligated to return the item. However, in an instance in which despair is presumed either implicitly or explicitly, the finder can keep the item. What is the Halacha in a case where an item is found with no presumption of forfeiture thereby obligating its return, yet forfeiture from the original owner comes in between the finding of the object and its successful return. Can the finder keep the object? Or since it came to him in a predicament requiring its return, the ultimate forfeiture is irrelevant?
It is implied in many halachos of Hashavas Aveida in Shulchan Aruch Choshen Mishpat סימן רנ"ט - רע"א, that only if ייאוש already occurred at the time of finding, is the finder not obligated to return the item. If at the time of finding the item ייאוש didn't yet occur, the finder is obligated to return the item even if ייאוש occurred prior to the return. The only difference would be the amount of transgressions the finder transgressed if he decides not to return the item. For further information to that point see שו"ע חו"מ סימן רנ"ט סעיף א.
An explicit source to the obligation of returning an item that was found prior ייאוש and ייאוש occurred before the return of the item can be found in בבא מציעא כ"א עמוד ב:
"בדבר שיש בו סימן כולי עלמא לא פליגי דלא הוי יאוש ואף על גב דשמעיניה דמיאש לסוף לא הוי יאוש דכי אתא לידיה באיסורא הוא דאתא לידיה דלכי ידע דנפל מיניה לא מיאש מימר אמר סימנא אית לי בגויה יהבנא סימנא ושקילנא ליה
The Gemara limits the scope of the dispute. In the case of an item on which there is a distinguishing mark, everyone agrees that despair that is not conscious is not considered despair. And even though we hear that he ultimately despairs of recovering the item, it is not considered despair, as when the item came into the possession of the finder, it was in a prohibited manner that it came into his possession. It is prohibited because when the owner learns that it fell from his possession, he does not despair of its recovery immediately. Instead, he says: I have a distinguishing mark on the item; I will provide the distinguishing mark to the finder, and I will take it."
We can see from here that if the item came to the the finder in a "prohibited manner", which as Rashi explains means before ייאוש, it doesn't matter if the owner ultimately was מתייאש, the finder is still obligated to return the item.