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 'clock' icon at the bottom of Phantom to view the recent activity tab, then find the pending transaction in question. 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.