A 19th-century prison and courthouse with a reputation as one of the most haunted places in Scotland.