It is a highly scientific treasure finder method. Albeit ... un-discovered science, of course :/ But not to worry: Some day science will come along and explain how it finds treasure !
That's a "magnetic dip needle" or just "dip needle."
A "Spanish dip needle" is the dowsing device shown in post #2. They first showed up prior to 1900, possibly during the Klondike rush. The stuff in the glass vial is invariably pyrite, passed off as real gold. I own 3 of these things. Also have 2 magnetic dip needles which are somewhat useful, unlike the Spanish variety.