Backwards, the legality is not prohibited.
“[Congressional jurisdiction of power]
is limited to certain enumerated objects, which concern all the members of the republic, but which are not to be attained by the separate provisions of any.” – James Madison, Federalist 14
The powers delegated by the proposed Constitution to the federal government are
few and defined . . . to be exercised principally on
external objects, as war, peace, negotiation, and foreign commerce.” – James Madison, Federalist 45
“The Constitution allows only the means which are ‘necessary,’ not those which are merely ‘convenient,’ for effecting the enumerated powers. If such a latitude of construction be allowed to this phrase as to give any non-enumerated power, it will go to every one, for there is not one which ingenuity may not torture into a convenience in some instance or other, to some one of so long a list of enumerated powers. It would swallow up all the delegated powers, and reduce the whole to one power, as before observed” – Thomas Jefferson, 1791
“This specification of particulars [the 18 enumerated powers of Article I, Section 8] evidently excludes all pretension to a general legislative authority, because an affirmative grant of special powers would be absurd as well as useless if a general authority was intended.” – Alexander Hamilton, Federalist 83
No legislative act … contrary to the Constitution can be valid. To deny this would be to affirm that the deputy is greater than his principal; that the servant is above his master; that the representatives of the people are superior to the people themselves; that men acting by virtue of powers may do not only what their powers do not authorize, but what they forbid.” – Alexander Hamilton, Federalist 78