All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and messenger.
If your prostration of forgetfulness was carried out before the Tasleem (i.e. salutation ending the prayer), it is considered part of the prayer. In case of being in a state of minor ritual impurity (i.e. passing wind, urine or stools and impurities that invalidate the prayer and require ablution), during the prostration of forgetfulness in this case, your prayer becomes invalid. Hence, you should have left the prayer to redo the ablution in order to re-perform the prayer.
However, if you performed the prostration of forgetfulness after the Tasleem, then it is not considered part of the prayer. Your prayer is valid in such a case, since the minor ritual impurity occurred after the completion of your prayer. In this case, you should redo your ablution and perform the prostration of forgetfulness only.