Necrophilia

a pathological attraction to dead bodies, especially sexual attraction or intercourse

Necrophilia is a paraphilia of being sexually attracted to dead bodies. Some necrophiliacs have sex with dead bodies. It is usually considered bad. It is illegal in many parts of the world, but not all.