Did the Buddha have special instructions to deal with masturbation? Did he teach special ways to handle those sexual lusts, did he prohibit it, or just not paying any attention to it? If so what were they?
he didn't prohibit it for secular people, it's not even subsumed under sexual misconduct
but since it's a lustful urge and act it is unwholesome and unskillful, and those need to be handled using the Right effort

[i]&quot;There is the case where a monk generates desire, endeavors, activates persistence, upholds &amp; exerts his intent for the sake of the non-arising of evil, unskillful qualities that have not yet arisen.
[ii] &quot;He generates desire, endeavors, activates persistence, upholds &amp; exerts his intent for the sake of the abandonment of evil, unskillful qualities that have arisen.
[iii] &quot;He generates desire, endeavors, activates persistence, upholds &amp; exerts his intent for the sake of the arising of skillful qualities that have not yet arisen.
[iv] &quot;He generates desire, endeavors, activates persistence, upholds &amp; exerts his intent for the maintenance, non-confusion, increase, plenitude, development, &amp; culmination of skillful qualities that have arisen: This, monks, is called right effort.&quot;

Maggavibhanga Sutta (SN 45.8)
Four Right Exertions
avoid situations and sensory stimuli which may provoke sexual desire, at that guarding of the sense doors is helpful
when and if it still arises think of the drawbacks which giving in to the urge may bring, contemplate its impermanence, develop understanding that it's going to eventually subside anyway, so that it loses a degree of its attractiveness and immediacy