Is a nocturnal emission, also known as keri, a sin? If it happens to you at night, is teshuvah necessary?
The Kitzur Shulchan Aruch (151:5) calls it a sin indeed, but an involuntary one.
If, God forbid, you had a seminal emission at night, upon waking up from your sleep you should wash your hands and say with a contrite heart, "Master of the Universe I have done this unwittingly but it was due to sinful thoughts and sinful reflections; therefore, may it be Your will Adonoy, my God, and the God of my fathers, to erase this iniquity [avon] through your great mercy, and save me from sinful thoughts, and from similar occurrences forever and ever. Amein, so may it be Your will." If you wish to avoid this sin, [...]
see 151:6 and following for ways to avoid this issue.
guardyoureyes.com expands on the issue and explains it is involuntary, there is no punishment involved but it requires tshuva
A nocturnal emission is something that occurs by itself, against a person's will, and therefore the person is not considered to have committed a willful transgression and there is no punishment involved.
Nonetheless, t'shuva is certainly appropriate, especially if a person looked at things he shouldn't or had lustful thoughts during the day. [...] The holy Baal Shen Tov teaches that if a person has an emission without any cause or lustful thoughts, he should not worry because he was under a sentence of death for some other sin, and now, because of the great sorrow he feels in his heart over the wasting of semen, his broken heart takes the place of death, and he is absolved from the decree that was upon him.
see further there for additional considerations
Our Sages teach us that these emissions come from thinking impure thoughts during the day. Based on that, you should have to repent