Because the gift of sex wasn't given by God for private self-indulgence. Masturbation is an abuse of sex and a fundamentally selfish act. Given the need for fantasy that accompanies it, it also encourages the objectification of  men and women as sources of pleasure.