Bitcoin Core doesn't maintain an index of transactions which are not relevant to you by default to save space and processing time.
You need to run your node with
txindex=1 in the configuration in order to create one, and changing the option on an existing node requires you do do a
bitcoind -reindex. A reindex is equivalent to doing a full network sync again but will use all of the block files you already have on disk for the process. When this is complete you will be able to look up arbitrary TXID using the
getrawtransaction RPC (
gettransaction only applies to transactions in your wallet).
$ bitcoin-cli getrawtransaction 74cffe12b2d58ac2e2bc13de5519428639267e2faffb85bbbfec60d8be7cdb50 1