Can you convert a headphone into a metal detector coil?
A headphone, no.

You can connect a proper coil to an earphone output, and a resonant coil to the microphone input.

You connect (in software) the microphone input to the coil earphone output.  Give the microphone signal a little amplification (in software.)

If the resonant frequency of your resonant coil is in the range of the earphone output and microphone input, then the whole thing will oscillate at the resonant frequency.

The amplitude will vary (somewhat) when metal objects are placed near the coils.

I don't know if the variation is enough to make a reliable metal detector.  I found that the amplitude only changes by maybe 15 to 20%.  Maximum change is if you plop a large metal object right in the middle of one of the coils.  At a distance of several centimeters, the variation is hard to measure.



Because of the conversion delays and the software delays, it can take seconds for the oscillation to build up.  It can also take a noticeable time for a piece of metal to affect the resonance.



In case you were wondering:  I spent a couple of evenings last week doing this very thing with a couple of coils and my PC.  It "works" in the sense that you can detect something.  There are probably better ways to do it, though.