think of bitcoin like this:
we have 3 things:
1. a box that is locked
2. the condition that needs to be satisfied for the locked box to open
3. the secret that can satisfy that condition and open the lock
when the sender sends coins, they are putting those coins in that lock box and set the lock to a certain condition they like. in order to set a condition in a way that only a key (#3) can open without knowing the secret itself the sender has to know something about that secret. that something is the result that is calculated with an irreversible function.
in asymmetric cryptography (ie. ECC in bitcoin) that irreversible function is point multiplication that returns a public key of that "secret" aka the "private key".
so now the sender sets that condition to this:
only the one with this public key shall open this box
now that we are thinking in terms of "conditions" and satisfying them you can set that condition to anything else. for example you can set it to a mathematical equation and set the condition to
only the one with the answer to this math question can open this box
one thing that we do nowadays is that we add another step to that condition, and that is requiring a hash. so the above condition changes to:
only the one with this public key that also has a hash equal to this (....) shall open this box
the first code snippet is called P2PK scripts where the "locking script" aka the "scriptpub" contains the public key itself. these are old and although still valid they are not used anymore.
and the final code snippet is called P2PKH scripts where the "locking script" contains the hash of the public key. that is being transferred between users in a human readable format called "addresses".
there are more scripts some of which have equivalent addresses such as P2SH, P2WPKH,... each with different type of conditions that needs to be satisfied.