Transactions typically complete quickly (within a matter of seconds or minutes), so if you want to cancel a transaction you'll need to act quickly. Tap on the ⚡ icon on the bottom right of Phantom, then find the pending transaction in question. Then tap on the transaction and click Cancel.
Note that this is simply an attempt to cancel, the transaction may still confirm due to the nature of the underlying blockchain and how transactions propagate through the network. This is for Ethereum and Polygon networks (EVM) only.