Assalam o Alalikum rahamtullahi wa barakuthu.
It's only recommended not oblgiatory, but in some cases, if a person feels lustful and cannot control which put him / her to danger of zina or masturbation, but can afford to get married and able to fulfil its reponsibilites, it becomes obligatory. If one is unable to afford, fasting is option, as it slows lust down. Dikhr and duas also helps against lustful thoughts. Shaytan is trying his work to make us commit immoralities.
Allah knows best.
JazakAllah khair