Hello dear,
First of all remove all myths & misconceptions from your mind about
masturbation.
In fact, Masturbation is completely normal & doesn't have any bad effect to the body and mind, unless you get addicted to it.
As you are experience difficulty in gaining weight and have a good body built, it will be better to rule out causes of
underweight.
Investigations like
complete blood count,
thyroid profile, estimation of blood sugar level will be helpful to rule out any chronic infection,
hormonal and metabolic causes.
Moreover, you should not compromise on routine healthy food such as:
1. Consume more of natural diet like fresh fruits, green vegetables, milk, eggs, wheat, etc.
2. Avoid oily and junk food.
3. Stay away from smoking & alcohol.
Wishing you a healthy life.
Take care.