If you don't hear even a click coming from the starter solenoid when this happens, as you try to fire up the engine, there could be a loose or corroded connection or wire between the battery and ignition switch, or switch and starter solenoid. When this happens, put the ignition key in the Start position while checking for voltage at the solenoid. Disable the fuel system [pull the pump fuse] to prevent it from starting while testing. Use a test light or multimeter. If there's no voltage, trace the circuit back to the switch. You may need the vehicle repair manual for your particular model to identify wires. With intermittent faults, this is usually a loose connection or wire.