VCs could not see any other reason to raise more money and Huggingface was not growing as fast as they thought to justify the valuation or the next fundraise.
So they might as well get Nvidia to save them from the VCs pressurizing them.
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.