One explicit mention of a ghost appears in the Talmud Ketubot 103a. The Talmud records that every week Rebbi used to return to his house after he died. The Talmud, however, does not record what Rebbi used to do when he came back. The Sefer Hassidim states that Rebbi was different than other dead people in that he was considered almost fully alive. Rebbi, according to the Sefer Hassidim, would make Kiddush for his family.
A much later instance of an interaction with a ghost is found in R. Pinchas Katzenellenbogen’ s (1691-1765/1767) Yesh M’Nechalin. R. Katzenellenbogen happened across a man who had the last two of his fingers bent back and connected to his palm. R. Katzenellenbogen inquired whether the man was born that way. The man explained that he was not and instead this happened when he had attended a fair. There were hundreds of people in a large room preparing for the next day’s events. Suddenly, the door of the room opened on its own. Standing at the doorway was a women dressed in tachrichim (death clothes). One person, screamed that it was his dead mother. Someone got up and slammed the door shut only to have the door open by itself again with the woman standing there. This man then went and pushed the “ghost” and from that day on his fingers were permanently connected to his palm.
Continuing on the theme of dead or other beings which interact with those still alive, we come to a rather strange question which has occupied the minds of many people for the last 800 years. The question is what is the status of someone who has intercourse with a demon? The first to mention this question is R. Isaac of Vienna (1200-1270) in his work Or Zarua. He states that intercourse with a demon is halackically meaningless. He cites a midrash which has a hassid (pious one) who was seduced by a demoness on Yom Kippur. Afterwards he felt very bad about this, but Elijah the Prophet visited him and asked him why he was sad. After the hassid explained what happened Elijah said don’t worry it was only a demon. The Or Zarua therefore says as Elijah appeared to him and he told him it was ok, intercourse with a demon is not a problem.
Now, the Or Zarua was not addressed at an actual question, however, R. Meir of Lublin (1558-1616) was asked about an “actual” case where a woman had intercourse with a demon and thus could she remain married to her husband. Although R. Meir was unaware of the Or Zarua he independentally came to the same conclusion – she was still permitted to remain married as intercourse with a demon has no effect. Least one say this is all in the realm of theory or not followed, the Beit Shmuel the classic commentary on Shulhan Orach Even haEzer quotes this law of R. Meir of Lublin (Even haEzer 6:17).
The question of intercourse with a demon seems to have come up without respect to the local or time period. R. Hayyim Yosef David Azulai (Hida) discusses “groups of women who go out to the forest” and conduct rituals with music and it seems they were visited or engaged in intercourse with demons. The Hida follows the ruling of R. Meir of Lublin and permits these women.
In Hungary in the 19th century there was a celebrated case where a woman became pregnant while her husband was away and she claimed the “father” was a demon. It appears the child was not deemed a mamzer (bastard) and the woman was allowed to remain married.
Now, there were some who questioned this whole line of reasoning and said that if one engages in intercourse with what appears to be human even if they are a demon it is of no moment. Thus, a married woman would be prohibited to remain married. The first to come to this conclusion was R. Yitzhak Binyamin Lipman (17th century) in his Nahlat Binyamim. Additionally, R. Yosef Zechariah Stern says if one follows the above rulings, what is stopping anyone who commits adultery to just claim it was a demon.
Moving on from demons, we now go to beings created via the Sefer Yetzirah. The Sefer Yetzirah (Book of Creation) is a work which allows via manipulation of various names of God to create things. Many have dealt with the halakhic status of such creations. For instance, R. Meir Leibush (1809-1879) in his work the Malbim says the reason Abraham was able to give the angels milk and meat together was Abraham did not give them meat from a born cow. Rather, the Malbim points to the verse which says “the calf which he [Abraham] made.” Malbim explains the words “he made” are literal, i.e. Abraham created the calf via the Sefer Yetzirah and thus was able to feed them both this meat and milk at the same time.
R. Isaiah Horowitz in his work Sheni Luchot HaBrit (Shelah) similarly understands the controversy between the brothers and Joseph. Specifically, Joseph, according to some Midrashic sources three negative things about the brothers – they at ever min ha-hai, they engaged in intercourse with Canaanite females and they embarrassed the children of the servants. The Shelah explains all three were based upon the Sefer Yetzirah. He explains that the Sefer Yetzirah was written by Abraham and passed on to Isaac and then to Jacob. The brothers, however, felt the sons of the servants were not worthy of such an important work (thus speaking ill or embarrassing them). Additionally, the brothers acted on the book and created animals which they ate from before killing them as there was no need being they were created via the Sefer Yetzirah. Further “it is possible that the tribes [the brothers] had created a woman” and it was these things Joseph saw and misunderstood to be regular beings. Again, according to the Shelah, intercourse or otherwise with beings from other worlds pose no halakhic issues. It is not surprising the Shelah took this position as the Shelah’s teacher was R. Meir of Lublin the one who permitted the woman who had intercourse with a demon to remain married.
Perhaps the brothers were not the only ones to make women for this purpose, it is recorded (albeit much later) that R. Solomon Ibn Gabriol (1021-1058) created a woman to “serve” him. But, when the authorities found out he was forced to show it was merely wood and not a person.
At the end of the forgery Niflot HaMaharal (the most comprehensive source for the false legend the Maharal of Prague created a golem) there is a discussion of various aspects of a golem. For instance, whether a golem would create impurity after it was “killed” (it would not) and the like. In regards to intercourse they state that “a golem can not reproduce nor does it have desires for the opposite sex.” It would seem that in the Paul Wegner 1920 silent movie classic "Der Golem" he disagreed with that premise. Part of the plot line is the Golem falling in love with the Maharal’s daughter; the nobleman’s son also does and she in fact runs off with him only to have the Golem rescue her. (It seems the Simpsons also follows with a similar plot line.)
As a final note, it is worthwhile mentioning that going the route of trying to connect with the other world does have it perils. R. Yaakov Ettlinger, in his Binyan Tzion describes a case where a woman met a man who told her he was Elijah the prophet and through their union the Messiah would be produced. The woman believed him, only to find out after the fact the person was con man. R. Ettlinger deals with whether in such a case she can remain married to her husband. So, ultimately one should make certain they verify the credentials of any demon, golem or ghost prior to engaging in any questionable acts.
Sources: Yesh M'Nechalin, 267-68; Hannah Sprecher, "Diabolus Ex-Machina: An Unusual Case of Yuhasin" in Jewish Law Association Studies VIII: The Jerusalem Conference Volume, 183-204; J.H. Chajes, Between Worlds: Dybbuks, Exorcists, and Early Modern Judaism (who although discusses the topic of intercourse with a demon appears to have been unaware of Sprecher's article which contains many more sources than Chajes cites or discusses); Moshe Idel, Golem, esp. pp. 213-241 (which was reprinted almost in its entirety in a Torah u-Madda Journal 9 (2000) article by Dr. John Loike; R. Yudel Rosenberg, Niflot HaMahral (Pitrokav, 1909), pp. 71-74; R. Yaakov Ettlinger, Binyan Tzion, no. 164; Shnayer Z. Leiman, "The Adventure of the Maharal of Prague in London; R. Yudl Rosenberg and the Golem of Prague." Tradition 36:1 (2002): 26-58.
 See the discussion in the R. Reuven Margulies edition how he could have been motzei them if he was dead. Sefer Hassidim, no. 1129.
 Interestingly, Idel in his book Golem, appears to have been unaware of the connection between the Shelah and R. Meir of Lublin.
 In the halakhic realm, most are already familiar with the well-known question first posed by R. Tzvi Ashkenazi and elaborated on by his son R. Ya’akov Emden, whether a golem could be counted for a minyan (quorum).
See the source.