If mining gets unprofitable, some miners leave, difficulty lowers, and miners who stayed are profitable again. The spiral could in theory be launched if bitcoin price consistently dropped after a lot of miners exit, but that hasn't been the case empirically (see Chinese miner exodus). There are enough big holders that understand how difficulty adjustment works, so I don't think such a spiral could ever happen.
And for 51% attack - suppose someone was buying all the ASICs sold by unprofitable miners for a long period of time (or just built his own ASICs plant and built lots of them). So now they are ready to start 51% attack on a low difficulty network. What happens?
A) difficulty jumps 2x, they are paying for electricity a lot and don't get compensated from the fees, so they've burned huge cash to buy ASICs and now burning cash on electricity.
B) the only thing they could really do with their attack is censor transactions (because double-spending their own funds at such a scale as to make the attack profitable is very hard to imagine).
So they're censoring some txs and thus not getting compensated for them and thus are burning even more cash. Meanwhile, the other 49% are not censoring and are taking those extra fees left on the table, and thus are more likely to survive and grow. The more attackers censor, the more pressure they get from honest miners.
This is from Erik Voskuil's book 'Cryptoeconomics', free version here: https://github.com/libbitcoin/libbitcoin-system/wiki/Cryptoeconomics
I can't say I agree with everything in the book, but this part seems very reasonable.