Does P2PKH substitute P2PK in any circumstances? Why? I know address(public key hash) was invented later than the official implementation released. Is it the reason?
Both P2PK and P2PKH were part of the first bitcoin 0.1 release, so that second point isn't true.
P2PKH is theoretically safer because the pubKeyScript only reveals the hash of the public key rather than the public key itself (which only matters in the case that the elliptic curve crypto involved is broken). So as long as you don't reuse the address, no-one else will know the public key before the money is spent.
All bitcoin addresses encode public key hashes so only P2PKH can be used with an address, as the public key is not known. P2PK were mainly designed for IP-to-IP payments, which is no longer possible in Bitcoin Core since version 0.8.0
Pubkey scripts are created by spenders who have little interest what that script does. Receivers do care about the script conditions and, if they want, they can ask spenders to use a particular pubkey script. Unfortunately, custom pubkey scripts are less convenient than short Bitcoin addresses and there was no standard way to communicate them between programs prior to widespread implementation of the BIP70 Payment Protocol discussed later.
To solve these problems, pay-to-script-hash (P2SH) transactions were created in 2012 to let a spender create a pubkey script containing a hash of a second script, the redeem script.
The basic P2SH workflow, illustrated below, looks almost identical to the P2PKH workflow.
Read More Bitcoin.org