Here's the pinout from the datasheet. You are interested in the right-side of the table.
Looking at the schematic of the connector, it can be understood that the pin-4 is normally connected to tip (pin-2), and is disconnected when the mating plug is inserted.
Here's your requirements:
- direct the signal to the headphone when it's inserted
- direct the signal to the speaker when the headphone is unplugged
In order to achieve this,
- The signal should go to pin-2,
- and exit through pin-4 to speaker amplifier.
When there's no headphone plug is present, the signal goes through normally-closed pin-2 and pin-4 to power amplifier. When the plug is inserted into the headphone jack, the signal will still be on the pin-2 therefore the headphone will get the signal. But since the pin-4 will be disconnected, the PA's input will be disconnected from the source. This will make the speaker muted. A proper pull-down resistor is needed across the PA's input in order to achieve proper mute and prevent humming/buzzing.