The Rambam wrote in chapter 7 that it is a measure of piety to inform the beit din, and they shall rent a place for a portion of their value for the sake of returning a lost object to the owners, for when he casts them into the marketplace they will deteriorate significantly; therefore, it is a measure of piety to inform even though he acted improperly. It is clear from his words that this is not according to the law but only a measure of piety, and even according to the measure of piety, he only needs to inform the beit din. However, some say that according to the law he must inform the owner of the produce first before he removes them, and if they were lost to an accident after he informed him, he is exempt, but if they were lost to an accident before he informed him, he is liable. And there is one who says that this is also the opinion of the Rambam: that after he removes them to the marketplace he is obligated to inform him so that he may see that the produce does not deteriorate, and if he did not inform him and they deteriorated, he is liable according to the law of garmi; rather, it is a measure of piety to inform the beit din even before he removed them so that they may rent a place for him, but he does not need to inform the owner of the produce beforehand because he does not want him to enter his house. And the "some say" also hold this way, that the notification is after he removed them to the marketplace, and they do not disagree at all [Sma and Bach]. But the wording of the Rambam does not indicate this, and it is found explicitly among the great Rishonim who hold that he does not need to inform him at all, and even if his produce deteriorates [Shita Mekubetzet], for since he acted improperly and misled him with deceit, he has no business with him, and "as he has done, so shall be done to him" is an absolute law and not merely a penalty [Tosafot Gittin 40b].
וכתב הרמב"ם בפ"ז דמדת חסידות הוא שיודיע לב"ד וישכירו במקצת דמיהם מקום משום השבת אבידה לבעלים דכשישליכן בשוק יתפסד הרבה ולכן ממדת חסידות להודיע אף שלא עשה כהוגן ומבואר מדבריו דזה אינו מדינא רק ממדת חסידות וגם ע"פ מדת חסידות א"צ רק להודיע לב"ד אבל י"א דמדינא צריך להודיע לבעל הפירות תחלה קודם שמוציאן ואם נאנסו לאחר שהודיעו פטור אבל אם נאנסו קודם שהודיעו חייב ויש מי שאומר דגם דעת הרמב"ם כן הוא דאחר שמוציאן לשוק מחוייב להודיעו שיראה שלא יתפסדו הפירות ואם לא הודיעו ונתפסדו חייב מדינא דגרמי אלא דממדת חסידות להודיע לב"ד אף קודם שהוציאן שישכרו לו מקום אבל לבעל הפירות א"צ להודיע קודם מפני שאין רצונו שיכנס לביתו והי"א ג"כ ס"ל כן דההודעה היא לאחר שהוציאן לשוק ולא פליגי כלל [סמ"ע וב"ח] ולשון הרמב"ם אינו מורה כן וכן נמצא מפורש לגדולי הראשונים דס"ל דא"צ להודיעו כלל ואפילו יתפסדו פירותיו [ש"מ] דכיון שעשה שלא כהוגן והטעהו ברמאות אין לו עסק עמו וכאשר עשה כן יעשה לו הוי דין גמור ולא קנסא בעלמא [תוס' גיטין מ:]: