The switch could be an issue but I am more suspect of the output speed sensor.
This is on the tailshaft of the tranny. Its held in with a bolt usually.

The issue could be the sensor proper or the plug may have dirty connections.

A scanner that can check stuff real time would be very helpful.

The sensor is a "Hall effect" unit and simply generates current based on the speed that the reluctor (Cog wheel inside) passes the sensor.

If the sensor has a short or an open the condition you describe will occur.

Get the codes pulled and see what shows before spending much time beating your head on the wall.

A real time scan that catches the beast in the act will make the fix easy.

Buttttt this sure sounds like an output shaft sensor issue.

Best

Robyn