The federal law was the culmination of a yearslong saga over TikTok, which the government sees as a national security threat due to its connections in China.