Terumot, Chapter Two, Mishnah Three
Our mishnah teaches other cases in halakhah where if someone did something prohibited unintentionally, he may benefit from it, but if he did it intentionally, he may not benefit from it.
1) One who immerses [unclean] vessels on Shabbat:
a) If unwittingly, he may use them.
b) But if intentionally, he may not use them.
2) One who separates tithes, or cooks on Shabbat:
a) If unwittingly, he may eat it.
b) But if intentionally, he may not eat it.
3) One who plants on Shabbat:
a) If unwittingly, he may keep the tree.
b) But if intentionally, he must uproot it.
4) But if during the sabbatical year, whether [it was planted] unwittingly or intentionally he must uproot it.
Section one: It is forbidden to immerse unclean vessels on Shabbat in order to purify them. The reason is that by immersing them he makes them usable. This is like completing a vessel which is forbidden on Shabbat. If he does so intentionally, he may not use them until after Shabbat is over, at a time when he could have immersed them in a permissible manner. However, if he did so unwittingly, meaning he either didnt know that it was Shabbat or he didnt know that he is not allowed to immerse vessels on Shabbat, then he can use the vessels immediately. Since he did so accidentally, he is not penalized by having to wait to use the vessels.
Section two: Similarly, one may not separate tithes or cook on Shabbat. Again, if he does so accidentally, he may eat the food immediately, but if he did so intentionally, he must wait until after Shabbat.
Section three: It is forbidden to plant on Shabbat. If one did so without knowing that it was Shabbat or that planting was forbidden, he may keep the tree. If not, he must get rid of the tree.
Section four: The one exception to the notion that if one did something unwittingly he may benefit from it is the sabbatical year. Albeck explains that Jews were suspected of working the land during the sabbatical year and then claiming that they had done so unwittingly. To prevent this, the rabbis made the rule especially stringent. Even if the Jew did the work unwittingly (or at least claimed to have done so), they are not allowed to benefit from it.