The output is the public key hash which is the address, the input is the public key. To spend, your wallet need to provide the public key and digital signature. In this regard, the public key and private key does not go beyond wallet, but are used in spending which makes the public key still very important.
Then, why storing public keys in the blockchain is needed if they can be safely skipped and calculated from signature and address?
The public key does not go beyond the wallet. The private key can generate the public key, but the public key that has been generated will be used for spending while in such process, private key only produces digital signature to spend.