At a high level, "flash loans" work by being acquired and repayed atomically. For example, this is useful for arbitrageurs
1. borrows a large amount of money
2. use the large amount of money to do arbitrage
3. pays back the large amount of money plus any fees
4. keep profits
and it does so "atomically", so if you can't repay the loan then the transaction fails and the whole thing never happened. or you could lose money if the transaction is successful but the trade is not profitable.like I said, I'm not an expert so someone correct me if I'm wrong
1. take out huge loan
2. do a bunch of things with huge loan and exhaust gas fees if any of them have don't have desired effect
3. replay loan
The only way miners can include the tx with the loan taken out, is if all the things the attacker does in step 2 do have the desired effect. Otherwise the attacker pays the gas fees of a failed tx.