Connecting NPN proximity sensor to rpi3 using reed relay
According to  LJ12A3-4-Z/BX datasheet the sensor should be powered by 6-36V, so 5V may be insufficient ( brown wire = +V, blue wire = -V/GND ). Connect coil of the relay between +V and output of the sensor ( black wire ). Also connect a pulldown resistor ( a few kohm ) between pin 18 and 20.