It's legal, and it's usually done to destroy a coin.
In the early days when alts were first being released, many were killed off by 51% attacks by bitcoiners who hated the thought of alts existing and thought that bitcoin should be the only crypto.
That's the reason why the only alt with sha256 is bitcoincash which didn't fork till 2018. The other alts adopted scrypt, which meant the bitcoin miners couldn't easily switch to mining alts and destroying them.
Back to the topic of discussion: it's unlikely that the top miners in bitcoin will attempt a 51% attack, because that would mean destroying their own business.