Hadith Q1305
وَفِيهِ مَا دَلَّ عَلَى أَنَّ الْبَيْعَ يَنْعَقِدُ وَإِنْ كَانَا عَاصِيَيْنِ بِفِعْلِهِمَا
And in this is evidence that their buying and selling will be concluded, even though they will be sinful because of this action.
Hadith 1305
Sayyiduna Abu Hurairah (may Allah be pleased with him) narrates that the Messenger of Allah (peace and blessings be upon him) said: "When you see someone in the mosque selling or buying something, then say this supplication against him « لاَ أَرْبَحَ اللهُ تِجَارَتَكَ » 'May Allah not make your trade profitable,' and when you see someone announcing a lost item in it, then say this supplication against him « لاَ أَدَّی اللهُ عَلَيْكَ » 'May Allah not return this item to you.'" Imam Abu Bakr (may Allah have mercy on him) says that if (the buying and selling in the mosque) was not actually taking place, then the statement of the Noble Prophet (peace and blessings be upon him) would have no meaning: "May Allah not make your trade profitable."