Tu Er Shen was originally a man called Hu Tianbao, who fell in love with a very handsome imperial inspector of Fujian Province. One day Hu Tianbao was caught peeping at the inspector through a bathroom wall, at which point he confessed his affections for the other man. The imperial inspector had Hu Tianbao sentenced to death by beating. One month after his death, Hu Tianbao is said to have appeared to a man from his hometown in a dream. He told him that, since his crime was one of love, the underworld officials had decided to correct the injustice by making him the god and safeguarder of homosexual affections. After his dream, the man built a shrine to Hu Tianbao, which became very popular in Fujian province, so much so that in late Qing times, the cult of Hu Tianbao was targeted for extermination by the Qing government.
A slang term for homosexuals in late imperial China was tuzi (rabbits), which is why Hu Tianbao is referred to as the rabbit deity, though in actual fact he has nothing to do with rabbits and (obviously) should not be confused with tuer ye, the rabbit on the moon.