So that means P2PKH or P2SH inputs could be spent respectively as P2WPKH or P2WSH? Transferring to segwit addresses isn't strictly necessary, as wallet software could be programmed to write transactions using the segwit address corresponding to the common public key of legacy addresses holding funds?
No, I misread your question.
The output type is specified by a script since addresses do not exist on the network. So P2PKH and P2SH outputs have a specific script that need to have specific input scriptsigs in order for them to be spent from validly. Likewise, P2WPKH and P2WSH outputs have their own output scripts which need to be spent in a specific way that is different from P2PKH and P2SH outputs.