If one took the lost object in order to steal it, and the owners have not yet despaired of it, he violates the positive commandment of "you shall surely return them," and he violates two negative commandments: the negative commandment of "you shall not steal" and the negative commandment of "you may not hide yourself." Even if he returns it afterward, he has already violated the negative commandment of "you may not hide yourself" and requires repentance. However, regarding the negative commandment of "you shall not steal" and the positive commandment of "you shall surely return them," he has rectified them by returning it to the owners, for the negative commandment of "you shall not steal" is a negative commandment transformed into a positive commandment, as it is written: "and he shall return the stolen object which he stole," and similarly the positive commandment of "you shall surely return them," for behold, he returned it. But the negative commandment of "you may not hide yourself" applies only at the time he does not take it to return it, and since he took it in order to steal it, behold, he has violated it and it is impossible to rectify it.
And there are some of our teachers who hold that he also did not rectify the negative commandment of "you shall not steal" and the positive commandment of "you shall surely return them," and that which he gave to him now is nothing but a mere gift. Their reasoning is that behold, in this object there are two prohibitions: the prohibition of theft and the prohibition of a lost object. This person who took it in order to steal it is considered, regarding the lost object, as if it were still lying on the ground, since he did not take it to return it. When the owners despair of it, he acquires it through despair like all lost objects found after despair. Even though a lost object that came into his hand before despair is not affected by subsequent despair, as I wrote in siman 262, that is because he is considered the watchman of the owner of the lost object, and therefore the despair of the owners is not effective since the watchman stands in his place and the watchman did not despair, and his despair is like a mistaken despair. But when he took it in order to steal it, it is acquired by him completely upon despair by virtue of the law of a lost object [the Ramban in the name of a Gaon and the Shach, and the difficulty of the Ketzot HaChoshen and the Netivot HaMishpat is resolved, and examine this closely].
נטל את האבדה ע"מ לגוזלה ועדיין לא נתייאשו הבעלים ממנה עובר בעשה דהשב תשיבם ועובר בשני לאוין בלאו דלא תגזול ובלאו דלא תוכל להתעלם ואפילו אם יחזירנה אח"כ כבר עבר על לאו דלא תוכל להתעלם וצריך תשובה אבל הלאו דלא תגזול והעשה דהשב תשיבם תיקן בחזירתה להבעלים דלאו דלא תגזול הוא ניתק לעשה כדכתיב והשיב את הגזילה אשר גזל וכן העשה דהשב תשיבם דהרי השיבה אבל הלאו דלא תוכל להתעלם אינו אלא בשעה שאינו נוטלה להחזירה וכיון שנטלה כדי לגוזלה הרי עבר וא"א לתקנו ויש מרבותינו דס"ל דלא תיקן גם הלאו דלא תגזול ואת העשה דהשב תשיבם ומה שנתנה לו עתה אינה אלא כמתנה בעלמא וטעמייהו דהנה בחפץ זה יש שני איסורים איסור גזילה ואיסור אבידה וזה שנטלה ע"מ לגוזלה הוי לענין אבידה כמונחת בקרקע כיון שלא נטלה להשיבה וכשנתייאשו הבעלים ממנה קנה אותה ביאוש ככל אבידות הנמצאות אחר יאוש ואף על גב דאבידה שבאה לידו קודם יאוש אינו מועיל היאוש אח"כ כמ"ש בסי' רס"ב זהו מפני שנחשב כשומרו של בעל האבידה ולכן אינו מועיל יאוש הבעלים כיון שהשומר עומד במקומו והשומר לא נתייאש והוי יאושו כיאוש טעות אבל כשנטלה ע"מ לגוזלה נקנית לו לגמרי ביאוש מטעם אבידה [רמב"ן בשם גאון וש"ך ומתורץ קושית הקצה"ח וענה"מ ודו"ק]: