Analysis.
This question has never been squarely resolved by case law. An analysis would look to the U.S. Constitution (the pertinent parts of which are restated below) and case law under it, to determine if Congress has the authority to enact such a law or not including whether laws currently on the books affect it.
Caucuses and primaries are used by political parties as part of their process for determining their Presidential nominees, and the only constitutional acknowledgement that they exist, or are subject to federal regulation is in the 24th Amendment. Political parties also have a 1st Amendment freedom of association interest in choosing their nominees as they see fit, subject to reasonable regulation in an area of law that is not well spelled out in case law.
On the the other hand, caucuses and primaries are government regulated, mostly at the state level, because their results have an officially recognized role in Presidential elections under state laws regulating elections for Presidential electors, and primaries are generally conducted at state expense by state and local government officials, rather than by political parties acting autonomously. And, states have wide expressly granted discretion regarding how they conduct Presidential elector elections subject to the authority of Congress to prohibit various kinds of discrimination in the conduct of elections and to set the date of Presidential elections (a right that Congress has chosen not to strictly enforce allowing early voting, for example).
New Hampshire does have the authority to say what a political party must do to have its nominee recognized on its general election Presidential ballot, and when it will conduct its state primaries. But, it does not necessarily have the power to determine whether or to what extent a national political party will consider the results of that primary in the process of selecting its nominee for President. The Democratic party, for example, would probably be within its rights to award no delegates to its national convention based upon New Hampshire's primary election participants based upon the New Hampshire primary election, and to instead award New Hampshire delegates solely as "superdelegates" who serve ex-officio, or based solely upon an entirely privately funded and operated Presidential caucus it held in New Hampshire at a date of its choosing.
The flip side is that New Hampshire might be within its rights, probably, to decline to put a Democratic party national convention chosen nominee on its Presidential elector ballots, a retaliation, although arguably that would deny the rights of its citizens to vote in the Presidential election over which the federal government has more regulatory authority.
The exact details of any situation leading to litigation would matter a lot, and it isn't possible to predict with any great certainty how a challenge would come out, although it is possible to articulate what provisions of the U.S. Constitution (and with more research, what court cases (maybe a dozen or two are arguably pertinent), federal statutes and state statutes) would be pertinent to the decision. It is possible to advocate for an outcome within the range of legally relevant authority, but, in practice, a negotiated compromise that would not push up against the hard constitutional limits of the constitution, relevant statutes and cases would almost surely be reached before it came to that point.
For example, while New Hampshire might arguably have the right to refuse to put the Democratic nominee on the ballot because it didn't consider the results of its first in the nation primary in choosing its nominee, I very much doubt that New Hampshire officials would actually go that far, if push came to shove.
On the other hand, if Congress passed a law stating that the District of Columbia shall hold the first in the nation primary, as it is probably expressly authorized to do under the 23rd Amendment, that federal law would probably pre-empt New Hampshire's law on the point.
Relevant Provisions Of The U.S. Constitution As Amended
Article I, Section 4 of the U.S. Constitution might be relevant. It states:
The times, places and manner of holding elections for
Senators and Representatives, shall be prescribed in each state by the
legislature thereof; but the Congress may at any time by law make or
alter such regulations, except as to the places of choosing Senators.
Article I, Section 8 of the U.S. Constitution might be pertinent, it states in the pertinent part that:
The Congress shall have power . . .
To make all laws which shall be necessary and proper for carrying into
execution the foregoing powers, and all other powers vested by this
Constitution in the government of the United States, or in any
department or officer thereof.
Even more directly, Article II, Section 1 which states, in part, that:
The executive power shall be vested in a President of the United
States of America. He shall hold his office during the term of four
years, and, together with the Vice President, chosen for the same
term, be elected, as follows:
Each state shall appoint, in such manner as the Legislature thereof
may direct, a number of electors, equal to the whole number of
Senators and Representatives to which the State may be entitled in the
Congress: but no Senator or Representative, or person holding an
office of trust or profit under the United States, shall be appointed
an elector. . .
The Congress may determine the time of choosing the electors, and the
day on which they shall give their votes; which day shall be the same
throughout the United States.
Article VI states in the pertinent part that:
This Constitution, and the laws of the United States which shall be
made in pursuance thereof; and all treaties made, or which shall be
made, under the authority of the United States, shall be the supreme
law of the land; and the judges in every state shall be bound thereby,
anything in the Constitution or laws of any State to the contrary
notwithstanding.
The 1st Amendment to the U.S. Constitution might apply. It states:
Congress shall make no law respecting an establishment of religion, or
prohibiting the free exercise thereof; or abridging the freedom of
speech, or of the press; or the right of the people peaceably to
assemble, and to petition the government for a redress of grievances.
The 10th Amendment to the U.S. Constitution might apply. It states:
The powers not delegated to the United States by the Constitution, nor
prohibited by it to the states, are reserved to the states
respectively, or to the people.
Sections 1, 2, and 5 of the 14th Amendment to the U.S. Constitution might apply. These sections state:
Section 1. All persons born or naturalized in the United States, and
subject to the jurisdiction thereof, are citizens of the United States
and of the state wherein they reside. No state shall make or enforce
any law which shall abridge the privileges or immunities of citizens
of the United States; nor shall any state deprive any person of life,
liberty, or property, without due process of law; nor deny to any
person within its jurisdiction the equal protection of the laws. . . .
Section 2. Representatives shall be apportioned among the several
states according to their respective numbers, counting the whole
number of persons in each state, excluding Indians not taxed. But when
the right to vote at any election for the choice of electors for
President and Vice President of the United States, Representatives in
Congress, the executive and judicial officers of a state, or the
members of the legislature thereof, is denied to any of the male
inhabitants of such state, being twenty-one years of age, and citizens
of the United States, or in any way abridged, except for participation
in rebellion, or other crime, the basis of representation therein
shall be reduced in the proportion which the number of such male
citizens shall bear to the whole number of male citizens twenty-one
years of age in such state. . . .
Section 5. The Congress shall have power to enforce, by appropriate
legislation, the provisions of this article.
The 15th Amendment to the U.S. Constitution might apply. It states:
Section 1. The right of citizens of the United States to vote shall
not be denied or abridged by the United States or by any state on
account of race, color, or previous condition of servitude.
Section 2. The Congress shall have power to enforce this article by
appropriate legislation.
The 19th Amendment to the U.S. Constitution might apply. It states:
The right of citizens of the United States to vote shall not be denied
or abridged by the United States or by any state on account of sex.
Congress shall have power to enforce this article by appropriate
legislation.
The 23rd Amendment to the U.S. Constitution might apply. It states:
Section 1. The District constituting the seat of government of the
United States shall appoint in such manner as the Congress may direct:
A number of electors of President and Vice President equal to the
whole number of Senators and Representatives in Congress to which the
District would be entitled if it were a state, but in no event more
than the least populous state; they shall be in addition to those
appointed by the states, but they shall be considered, for the
purposes of the election of President and Vice President, to be
electors appointed by a state; and they shall meet in the District and
perform such duties as provided by the twelfth article of amendment.
Section 2. The Congress shall have power to enforce this article by
appropriate legislation.
The 24th Amendment to the U.S. Constitution, which is the only one expressly recognizing the existence of primary elections, might apply. It states:
Section 1. The right of citizens of the United States to vote in any
primary or other election for President or Vice President, for
electors for President or Vice President, or for Senator or
Representative in Congress, shall not be denied or abridged by the
United States or any state by reason of failure to pay any poll tax or
other tax.
Section 2. The Congress shall have power to enforce this article by
appropriate legislation.
The 26th Amendment to the U.S. Constitution might apply. It states:
Section 1. The right of citizens of the United States, who are 18
years of age or older, to vote, shall not be denied or abridged by the
United States or any state on account of age.
Section 2. The Congress shall have the power to enforce this article
by appropriate legislation.
Collectively, these sections of the U.S. Constitution give the federal government considerable legislative authority to regulate state elections for federal offices.