Article III section 2 of the US Constitution.
The judicial Power shall extend to all Cases, in Law and Equity, arising under this Constitution, the Laws of the United States, and Treaties made, or which shall be made, under their Authority;—to all Cases affecting Ambassadors, other public Ministers and Consuls;—to all Cases of admiralty and maritime Jurisdiction;—to Controversies to which the United States shall be a Party;—to Controversies between two or more States;—between a State and Citizens of another State,—between Citizens of different States,—between Citizens of the same State claiming Lands under Grants of different States, and between a State, or the Citizens thereof, and foreign States, Citizens or Subjects.
Congress can say the President has done something illegal. The President can say they have not done anything illegal. You now have a controversy. The Constitution indicates that the judicial power will now handled it.
To sue someone or something means in the strictest of senses, "I wish to bring this matter before a court of law." So a controversy has arisen, the courts have the right to review it. The Constitution outlines who is allowed to do what, and nobody is allowed to step out of that. So if a controversy wasn't present, the the courts would have no jurisdiction.
Congress believes there is a controversy and thus they are suing. That means they wish to bring the controversy to the thing that's indicated in the Constitution to settle such a thing.
However, you run into the very first question, "Is it a TRUE controversy? Or is it just a disagreement?" This is the no political questions doctrine. Congress and the President routinely disagree on things. The Courts aren't there to settle a disagreement. It has to be a genuine controversy. That means "The law objectively says XYZ. The President specifically did not do XYZ. Ergo, this is not a disagreement but a President who is not following the letter of the law which is a controversy."
So like anything Congress brings up, the President is allowed to say it's not a controversy. What the ruling on that question, the President or Congress can appeal it. If the appeal isn't good enough, the Supreme Court gets to make a final ruling. Once a controversy has been established, THEN, there's the actual case. The the final decision of the case can be appealed and then brought before the Supreme Court.
Rarely do we actually get that far with things because you can't get all that stuff done within a single President's term. And the real reason a Controversy is attempted is to get discovery and things the President has been doing on the public record. Depends on what Congress is looking for. Perhaps they want to ensure Musk stays out of politics forever, a deep and heavy discovery process into him may just do that.
But Congress can bring a suit to the Courts so long as it's within the powers of the Constitution for Congress to do so.