Can you explain how to do this?
Depends on your wallet software. With Bitcoin Core, then
createrawtransaction has a data field you can specify which will create an OP_RETURN output. In Electrum, you can simply write OP_RETURN followed by the hex encoding of whatever data you want in the address field.
Do I understand correctly that there are transactions that cannot be spent even knowing the private key?
OP_RETURN outputs do not have private keys associated with them. OP_RETURN is an opcode (a type of command used by the bitcoin network) which marks an output as invalid. There is no private key, and any funds sent to OP_RETURN outputs can never spent. They are provably burned. You can create OP_RETURN outputs without burning any coins, though, just by paying the usual transaction fee.