In the United States, I read that people that sell Bitcoin for USD will pay taxes based on the difference of when you bought and sold. How does an exchange like Coinbase know how much your BTC is worth if you just send BTC to them and you sell it immediately? RobinHood or PayPal do not allow you send crypto to other addresses, so they know the Bitcoin price when you bought and sold.
Tax questions should largely be off-topic here, as they are so jurisdiction-specific. But nonetheless, a general answer is sort of possible here:
In many jurisdictions, you will be liable to pay capital gains taxes when you make profit buying and then later selling some asset. This tax is calculated when you report your taxes to your local tax authority, so you simply need to keep track of the prices you buy and sell your bitcoin for.
The exchange you buy/sell from will probably be keeping track of this as well, but in some cases they may only have partial info (eg, the sell only). So you will need to keep track of the rest of the info yourself, in order to correctly report your investment activities.