> How would they prevent the market from devaluing the stock as more is printed?
The important way to think about it is not price-per-share but price-per-percent. The share price on the market likely would fluctuate. It would be diluted as you pointed out, but if the attacker really wanted to own it, they're going to have to be the highest bidder on the market for a majority of the shares. They already have to over-value those shares, since that share that brings them >50% is WAY more valuable to them than every share leading up to it.
If Elon owned 15% and wanted to reach 50%, he has to buy 35% of the shares to reach control (50%). If you double the number of shares of existing shareholders but not Elon, then Elon would own 7.5%. Now he has to buy 42.5% of the company. Assuming the absolute value of the company didn't change, Elon will have had to buy 15%+42.5%=57.5 of the company just to buy what was 50% yesterday. This effectively adds a 7.5% premium to buy a controlling amount, and that premium is divided up among shareholders who sold out post poison pill.
Oh, and along the way, the demand to buy all those shares means that the attacker has to be the highest bidder. And that kind of demand would create a massive shift in the market. If enough of shareholders thought the price was too low, (or realistically a small fraction of them, since companies like index funds managers don't actively trade shares), they wouldn't sell to the attacker and the attack wouldn't be possible - so an attack has a huge upwards pressure on the price. every share gets more expensive than the last.
> it seems unlikely that a failed takeover would change the stock price for longer than a news cycle. All the fundamentals are unchanged, so it's more likely the price would return to what it was before.
Elon is basically a meme, just look at this tweets affect on the markets for things like crypto. Elon being associated with something makes it more valuable. When Elon announced he was getting involved and buying shares, they went up in price double-digit percents. If he said "jk i don't think twitter is valuable" AND dumped a huge load onto the market at once, the price would certainly crater for a while, even if, yes, one day it may return to "normal". But few investors would be happy to stomach that crash, especially since the board is judged in part on share price.
* technically you need >50%, but the math is way rounder and easy to rationalize to use 50 not 51.
* also, I don't know the details about the specific poison pill for twitter, but I'm just picking nice numbers for the math purposes
* this is also a big critique of passively managed funds economically - they limit the market dynamic and force buying/holding of companies that "the market" otherwise doesn't value