In the case of GitHub, it was likely for data reasons + wanting to own where developers do work (VScode + Github).
In the case of HuggingFace, honestly not sure as I'm not familiar enough with their business. But I can assure you that Nvidia didn't buy them for 13 billion cause HuggingFace were desperate. When you're desperate, you sell for less not more.