Occam's Razor suggests this was due to both a matter of national security from the perspective of the intelligence community and pressure from US companies who have struggled to outcompete TikTok. Basically an "everybody wins" move for the powers that be.[1]
China understandably didn't want to lose its influence, and ByteDance didn't want to give up this incredibly valuable asset, so they said "We'll call your bluff and fight you on the basis of the freedom of speech".
The US government then moved to get a law signed that carves out a very specific way to force ByteDance's hand. I'm sure there were lots of lawyers involved and maybe some back channel with the SCOTUS to make sure this was done in a constitutional manner so that it would survive a suit from TikTok which was all but guaranteed.[2]
That plan worked, so now ByteDance/TikTok/CCP are again forced to sell, except they come to this round of negotiations in a much worse position than they were originally. This makes it better for the many, many buyers that have come out of the woodwork and made public and private bids for the asset.
But these buyers don't want the actual value of TikTok to drop to zero, so they must also be pressuring president-elect Trump to reinstate the app so that it can continue to be used by Americans and therefore remain valuable, so that when they actually get their money's worth when it inevitably changes hands.
Trump isn't restoring TikTok so that it can continue to operate as in the "status quo ante bellum negotii". He's restoring it so that {insert buyer} can claim the spoils in a few weeks.
---
[1]: We can debate whether "everybody wins" includes the US population, but I think they do, because Chinese influence over US culture is strictly worse than US influence over US culture, seeing as incentives are by definition irreconcilable and therefore always worse if under control of the CCP.
[2]: It stands to reason that all of the US government and the top echelons of business and finance is operating in concert here to drive the outcome they want, which is to remove the influence of the CCP over young American minds and to benefit from forcing the asset to be controlled by a US entity.