I'm almost as confused as you are.
You say you want to detect 5volt of a PNP sensor with pin12.
And then you configure pin12 as an output.
Post a link to the sensor.
Post a diagram of how you have connected it. With all the voltages and parts values.
Tell us which Arduino you're using.
Post your full code.
We are not mind readers.
Leo..
A PNP sensor outputs (sources) voltage that you can read with an Arduino input.
A PNP sensor outputs almost the same voltage as the sensor's supply.
So if you power the sensor from 12volt, almost 12volt is coming out of the sensor's output (when activated).
That (12volt) is dangerous for an Arduino pin, so you have to use a voltage divider to cut that to <=5volt.
If your sensor runs on 12volt, use the diagram from post#14 in this recent thread. https://forum.arduino.cc/index.php?topic=400763.0
Leo..