Cults and Religions
This movie offers some insight into how primitive cults with animal deities and various fetishes/taboos may have come about (and eventually evolved into a more advanced religion).
As Dr. Dysart says, Alan knows no science or engineering to make the world real, he has no culture, and no literature. Living in a void, he has to invent a mythology to make some sense of it all. Primitive people had to do much the same thing, and one would suppose that a great deal of their cultic fixations and rituals involved displaced sexual fetishes in one form or another (just as Alan had).
In other words, Alan is not so much mentally ill but a savage living in the modern world. His pain was caused not by his obsession as such, but by the guilt he felt over the fact that it obviously didn't fit in with life and society around him.