I read the link. I am still not clear. In
scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
scriptSig: <sig> <pubKey>
The scriptSig contains the <sig> sender signature and <pubKey> sender public key, the scriptPubKey contains <pubKeyHash> which is the hash of receiver public key.
Then, how can the hash of sender <pubKey> matches with the receiver <pubKeyHash> ?
The scriptSig part is what the receiver uses to spend the money that they got from pay-to-public-key-hash. Because they're spending the money, at that point they'd be the new sender. The <pubKey> for this new transaction hashes to the receiver's <pubKeyHash> from the old transaction when they first got the money.
Here's an
example P2PKH transaction. It pays 0.00063664 BTC to my address with the script OP_DUP OP_HASH160 0507135dd0ec75f539b304d8641bf00372989b27 OP_EQUALVERIFY OP_CHECKSIG. Then, in the
next transaction, I spend that 0.00063664 BTC, and you can see in the input script (scriptSig) that there is both a signature and the public key that hashes to 0507135dd0ec75f539b304d8641bf00372989b27, which is the pubKeyHash in the script of the other transaction where I was the receiver.