Answer
(Fatwa: 109/109=M/1430)
Consult any hakim for wet dream and act upon his prescription. It is not bad if bad thoughts automatically come to mind, rather it is bad and prohibited to accommodate them and enjoy them. Therefore, one should repel such thought the moment they come in. Divert the mind to other things and recall the punishment of Allah. The best way to guard eyes, gain mental peace and protection from thought is to marry as soon as possible (if you are not yet married) and keep yourself busy in dhikr and tilawah in leisure time. Also, keep on reciting this dua:
أللھم إني أعوذبک من سوء الأخلاق والأعمال والأھواء والأدواء
Allah (Subhana Wa Ta’ala) knows Best
Darul Ifta,
Darul Uloom Deoband