If you do something while you are asleep, half-concious at the moment, is it a sin?
In order for one to sin mortally, three conditions must be present: 1) the act must be objectively sinful, 2) the person must know that it is sinful, and 3) the person must freely choose to act.
When one is asleep or even partly asleep, one cannot freely choose to sin–even if one is dreaming that one is sinning.
Fr. Vincent Serpa, O.P.