بسم الله الرحمن الرحيم
(Fatwa: 672/638/M=5/1438)
Masturbation is unlawful and heinous act. No doubt a haram work is sinister. Unlawful activity removes the brightness, spirituality and prosperity. But the reason that salah of forty days is not accepted due to it is related to wine. It is in hadith: “Whoever drinks wine, salah is not accepted from him for forty days.”
من شرب الخمر لم يقبلالله له صلاة أربعين صباحاً.
However, you should avoid masturbation and each and every unlawful practice. In-shaAllah, your prayer shall be accepted.
Allah knows Best!
Darul Ifta,
Darul Uloom Deoband