The literary genre described is the Gothic novel, flourishing from the late 1700s through the early 1800s.
Gothic novels employ horror, the supernatural, and the macabre to create atmosphere, mystery, and suspense. Typical elements include gloomy settings (castles, ruins), supernatural occurrences, psychological terror, and themes of isolation and madness.
These works laid the foundation for modern horror and speculative fiction.