
One of the sages asked Rav Sheshet: What is the rule for one who places his sexual organ into his own anus? Has he violated the prohibition against homosexual relations?
Rav Sheshet answered: I am distressed that you have asked about something which cannot take place in reality — for it is impossible for a man to place his sexual organ into his own anus.
Rav Ashi said of this: When the sexual organ is erect and hard, there truly is no technical possibility of placing it into one’s own anus. But it is possible when the sexual organ is not erect, when it is limp, and it would seem that one doing this act would, in this single act, be liable for two sins, for he is both the one penetrating and the one penetrated, so he is liable for both. This sage added his personal opinion: as in forbidden sexual relations, the Torah prohibits only cases in which the sexual organ is hard and erect. If he commits this act when his sexual organ is limp, he is not liable, and this is the rule for our case as well. But according to those who say one is liable for forbidden sexual relations had with a limp organ as well, the man in our case is liable.
(Babylonian Talmud, Tractate Sanhedrin 55a)