hello... the most likely issue is due to the adjustment of the shift interlock actuator on the right lower side of the steering column. ( the solenoid is #7 in the illustration below) the solenoid has an intermittent failure or there is a fault in the adjustment of the actuator rod.
IF your unable to get the actuator to function properly, then i'd replace it. the diagnostics of that solenoid are that, of the 2 wires going to it... 1 is a power when the brake is applied... and the other is a constant ground. if your voltages check out ok... then replacement of the solenoid is recommended.
you could unhook the linkage... and if necessary use a "plastic tie strap" to hold the arm the linkage connects to in place to allow operation of the shifter.
YOU MUST NOTE>>> this will allow the shifter to be operated without depressing the brake pedal if the system is disengaged in this fashion... so care should be taken after doing this.