Man who had sex with horses needs help, judge tells court