Please help me understand how this inductive proximity sensor works
They don't really give a internal diagram (which is problematic) in their datasheet:

Source: https://cdn.awsli.com.br/945/945993/arquivos/14_PROXIMITY_INDUCTIVE_18BY.pdf
I'll bet it looks like this (from similar designs):



simulate this circuit &ndash; Schematic created using CircuitLab
First off, you need a pull up on the output with the NPN, (they may have an internal one). You could put the opto in series with the external pull up. If you want inverted logic then use another NPN stage to invert it.

Source: http://sullystationtechnologies.com/npninverter.html