The solenoid sits on top of the motor. Inside is a coil around an iron plunger. Turn the key, current flows through the coil and it pulls the plunger in. On the end of the plunger is a copper disc. At the end of its travel, the disc bridges two heavy terminals, one from the battery and one to the motor. That's job one: the big switch.
The plunger also works a lever, sometimes called a fork, which pushes the pinion along its shaft and into the ring gear. That's job two: the push. The pinion moves first and the contacts close right at the end, so the motor only gets full power once the gears are meshed.
Two windings
Pulling the plunger in takes a lot of magnetism; holding it takes much less. So most solenoids have a strong pull-in winding and a weaker hold-in winding. The pull-in winding earths through the motor. Once the main contacts close, both its ends sit at battery voltage, so it switches itself off and only hold-in keeps working. That stops the solenoid overheating.
Cranking simulator Side-on cutaway
Step through one start. Watch which windings carry current, when the pinion moves and when the main contacts close. The thin coil along the top of the solenoid is the hold-in winding; the thick one along the bottom is the pull-in winding.