Hi, Welcome to Health care magic forum.
It might be
nocturnal emission, or
masturbation. the hardening and pain might be due to the erection of the penis, as the question suggests you aye about the age of 14 years.
Your psychological condition is more towards sex.Probably it is effecting your general health, and and physic.
The emission, and hardening are not a matter, it appears that you are thinking that it is a matter of sin, or some thing like that.
Stop, thinking about all this stuff, and try to divert your self to studies, or some work.
I advise you to take, more calories, fats, fries, and junk foods to some extent.Try to take food in 2 or 3 spells of heavy food.
Try to sleep for more time, but not all the time, practice, early to bed and late to rise, and try to sleep in the day time for a while.
Take more of green leafy vegetables, pulses, sprouts, and protein rich foods, to have a early recovery, and to have good resistance.
Wishing for a quick and complete recovery. Thank you.