By using leverage and/or derivatives.
Same way some smart Wall Street contrarians made money on the housing bubble nearly a decade ago.
But even that won't get you success in a 51% attack on Bitcoin. Currently the cost of the attack likely involves producing your own chips, ... about $500M worth of them at the present time. So you aren't doing this attack successfully, "without detection".
But let's take a hypothetical attack on an altcoin, ... one with decent liquidity, and doesn't have a prohibitively large amount of protection from the amount of mining. Let's use Ethereum Classic ($ETC), for example.
So you hold $30M worth of $ETC for use in the attack. You then acquire control, for one day, of 3.2 Th/s (Ethash) ... about 100,000 GPUs, worth about $40M. Start mining your private fork. Spend that $30M of $ETC on the private fork to an address you control. This will be the double spending that you release later.
Send $10M $ETC to exchanges where you then buy positions that are short $ETC, somewhere in the 3:1 leverage range. Send the remaining $20M $ETC to the exchanges. Aggressively sell, converting to BTC, and withdraw. Slippage, though after dumping $ETC, might leave you with a bit less than the $30M of $ETC that you started with, so estimate retaining maybe 70% of the value, or about $14M.
But then you sell/close your leveraged short position, making back maybe 200% profit (profit of $20M). Convert that initial $ETC capital and $20M gains to to $BTC and withdraw.
Then release the private fork which doubles spends, essentially reversing the $ETC the exchanges thought they received.
In summary here's your position:
Started out holding 1.7M $ETC (worth $30M). The $10M worth of $ETC sent to the exchange leveraged exchanges for shorting ended up returning $25M worth of BTC.
The $20M worth of $ETC sent to other exchanges for crashing the price ended up returning about $14M worth of $BTC.
After the attack is over, you have that $39M worth of BTC plus you still have the 1.7M $ETC you started out with at the beginning.
After a successful 51% attack, those might be worth just 20% of their pre-fork value. So that's maybe just another $5M of value.
What I didn't address was the cost of carrying out the attack. Perhaps renting 100,000 GPUs for the day cost $5M. Probably more. Who knows, it's never been done before, and probably impossible to execute. So maybe instead you'ld need to buy $40M worth of GPUs yourself.
So add that in, you needed $70M to carry out the attack ($30M of $ETC plus $40M to get the 100,000 GPUs).
After the attack is said and done you have $39M of BTC, $5M of $ETC, and $35M worth of GPUs ($5M lost as the box as these are now used GPUs).
That's not even a lousy 15% return on a $70M investment, assuming this is a one-and-done deal. And that's only if all exchanges allow your withdrawals in a timely fashion (withdrawing millions of $BTC can drain hot wallets and/or KYC checks imposing delays and/or account freezes). And if the short positions worked the way you had hoped.
And thus, this gives the explanation why we don't see 51% attacks performed for the purpose of cheating exchanges (yet).