Challah, Chapter 3, Mishnah 4. In the previous Mishnah we learned about a person who consecrates his dough: if he consecrated it and redeemed it before it became dough, or after it became dough - it is obligated in challah; but if the mixing of the dough took place while it belonged to hekdesh - it is exempt. Our Mishnah comes to teach a parallel ruling in the laws of maasros.
"Kayotzei Bo, Hamakdish Peirosav":
The Mishnah opens: "Kayotzei bo, hamakdish peirosav ad shelo ba'u l'onas hamaasros" - a person who consecrated his produce before it reached the stage called onas hamaasros, the point at which produce becomes subject to tithes. There is some discussion as to exactly which stage our Mishnah means by onas hamaasros, but for simplicity we can say that it refers to the point at which the processing of the produce is completed: with grain, the smoothing over of the pile of grain, and with other produce, at other points; in any case, the completion of the processing is what is called onas hamaasros.
The Three Cases in the Mishnah:
"Ad shelo ba'u l'onas hamaasros u'fedaan - chayavin" - he consecrated the produce before it reached onas hamaasros, and he also redeemed it before it reached that stage: the produce is obligated in maasros once it reaches onas hamaasros.
"Mishaba'u l'onas hamaasros u'fedaan - chayavin" - he consecrated the produce after it had already reached onas hamaasros, and afterward redeemed it: here too it is obligated in maasros after the redemption.
"Hikdishan ad shelo nigmeru, u'gemaran hagizbar, v'achar kach pedaan - peturin" - he consecrated the produce before its processing was completed, and the gizbar, the treasurer appointed over hekdesh, is the one who completed the processing, and only afterward did the owner redeem it from hekdesh: this produce is exempt from maasros.
The reason is stated explicitly in the words of the Mishnah: "shebish'as chovasan hayu peturin" - at the moment when the obligation of maaser would have taken effect, the produce belonged to hekdesh, and therefore it was exempt at that moment; and once the moment of obligation passed while the produce was exempt, it no longer becomes obligated in maasros even after it is redeemed.
In summary: Our Mishnah places the laws of maasros on the very same foundation as the law of challah in the previous Mishnah - everything depends on the status of the produce at the moment the obligation takes effect. If he consecrated and redeemed before onas hamaasros, or consecrated after the produce reached onas hamaasros and then redeemed it - it is obligated; but if its processing was completed by the gizbar while it was still hekdesh, then the moment of its obligation passed at a time of exemption, and therefore it remains exempt even after the redemption.