I have a raspberry pi receiving inputs with a 300k resistance connected between the voltage input (12V) and the gpio. When my python code is not running the voltage at the gpio is 1.7v, but when I run my code the voltage goes up to 5.4v. I tried to add another 300k resistor to see if I could lower the voltage at the gpio, but the voltage just dropped down to 5.2v. The pi still runs perfectly when receiving this amount of voltage. I want to understand why the circuit is behaving this way. I also tried using a 900k resistance before the gpio input and the voltage is still 5.1-5.2v at the gpio.
Adding a resistor in series will not drop the voltage. It will simply reduce the current.
Fortunately you seem to have limited the current to a level which the Pi's GPIO protection circuitry can handle. However you are risking destroying the Pi when you connect any voltage more than 3V3 to a GPIO.
One way to produce a safe voltage for the Pi GPIO is to use a resistor divider circuit.