Halacha forbids deriving any sort of benefit from the remains of a deceased person. The Rishonim (Medieval Halachic authorities) debate the question of whether or not this prohibition applies to the hair of a deceased individual. The Rambam (Rabbi Moshe Maimonides, Spain-Egypt, 1135-1204) maintained that hair should be seen as something that grows from the body, rather than part of the body itself. As such, it is not subject to the prohibition against deriving benefit from a human corpse, and one may make personal use of hair taken from a deceased person. The Rashba (Rabbi Shlomo Ben Aderet of Barcelona, 1235-1310), by contrast, held that hair is considered part of the corpse, and one may therefore not derive any benefit from hair taken from a human corpse.
The Shulhan Aruch follows the stringent position of the Rashba, and forbids deriving benefit from hair taken from a human corpse.
This issue is practically relevant with regard to the use of wigs of toupees. Very often, wigs are manufactured from hair taken from the remains of deceased people. Therefore, it is preferable when purchasing a wig or toupee to inquire as to the origins of the hair, and ensure that the hair was not taken from a human corpse. If it is discovered that the hair came from a corpse, one should not wear the wig or toupee.
If, however, there is no possibility of determining the source of the hair, then the wig or toupee may be worn despite the likelihood that it was produced from the remains of a deceased person. In such a case, we may apply the rule of "Sefek Sefeka" ("double doubt"). With regard to the hair used in making wigs, we have two factors that combine to result in a lenient ruling. First, as we saw, it is questionable whether hair from a corpse is forbidden for use in the first place. Second, even if we assume that hair does fall under this prohibition, there is a debate among the authorities as to whether this prohibition applies to the remains of gentiles, or only to Jewish corpses. Since two different points of uncertainty are involved, we may allow one to purchase and use a wig or toupee even if its source cannot be determined. Preferably, however, one should inquire as to whether the hair was taken from the remains of a deceased person.
This is the ruling of Rav Shemuel Pinhasi (contemporary scholar in Jerusalem).
Summary: One who purchases a wig or toupee should inquire as to whether it was made from hair taken from a human corpse, and, if it was, it should not be worn. If the hair’s origin cannot be determined, then one may nevertheless purchase and wear the wig or toupee.