Technically by the standards of the 1940s War Crimes trials and by the UN Charter, invading another country or going to war in most circumstances
is a war crime.
But its never that simple:
1) If you have ANY kind of UN security council resolution to even half-ass justify it, you can go to war. This is how the US went to war with Iraq and Afghanistan
2) If a country is not a member if the United Nations you can go to war with it, you can take all their stuff and do anything you want to it. This was
how the US was able to conduct its war on Serbia in the late 1990s.
3) Under the UN charter, "regional security groups" (like NATO) have vague but nearly unlimited power to intervene in countries within their "region". This
is how the US went to war in Libya. And earlier into various places within the Americas.
4) If you are an outside party and you get invited into the country by some group or organization within the country. Then you can kind of go to war.
5) Countries have a right to "self defense" which is vaguely defined and open to interpretation. But various countries have used this standard to start wars.
6) The "Fuck you" doctrine. In 1941, the British invaded and occupied Iran during world war II. Iran applied to the United States and its President FDR
under the terms of the US/Britain Atlantic Charter that this was wrong. FDR's response to Iran was that their neighbors were in trouble and that
"good neighbors" help each other in time of need. That even though the had been occupied by another country, it was a good occupation. The
same applies to the occupation of Iceland during World War II.
7) You can just not submit yourself to the international court for war crimes. This was the US strategy. If nobody can bring a case against you for
war crimes, there is no war crime.

If after the conflict the country you went to war with or its government no longer exists, their case under international law is moot.