Your keyswitch provider voltage to solenoid trigger wire. As solenoid retracts it both moves the starter Bendix up into the flywheel ring gear and also makes a contact plate across the two main terminals internally to activate the starter itself. When when you release the keyswitch the voltage to solenoid is no longer present and solenoid release the Bendix and move the contact plate away from the two main terminals deactivating the starter motor.