Haunted House inheritance.

You learn that a distant relative has died. You stand to inherit their fortune. But first, you must spend a specific period of time in a haunted house. What was the original source for this trope?

The Cat and the Canary, which started as a play in 1922 but the later films are more famous, sort of has this - the inheritor has to stay overnight, but it’s not a direct condition of the will (that is that they must stay sane).