Under Article I, Section 8, Congress has the power to declare war, raise and support Armies, provide and maintain a Navy, and organize, arm, discipline, and call forth a militia.
Using spies (human intelligence) is as basic to warfare and defense as any other weapon.
Spying on citizens is where things get murky.
And as much as many readers here may dislike the intelligence agencies, distinguishing between domestic and foreign targets in the internet age is not an easy problem to solve.
Especially considering they're damned when they go too far (e.g. Prism) and damned when they don't (9/11).
Spying and other intelligence gathering was, at the time, seen as a "necessary and proper" part of running a military. And the Constitution explicitly authorizes providing for "the common defense", explicitly authorizes the existence of military forces, and grants the power to make laws "necessary and proper" to carrying out these authorizations.
Spying and intelligence are still, in the present day, seen as a matter of national defense. NSA is explicitly under the Department of Defense, for example. CIA is civilian, but is still framed as serving a defense/national security purpose (thus Constitutionally justifiable) and scoped to be foreign-facing (domestic intelligence is primarily the FBI's province, "necessary and proper" for enforcing federal law).
However, the Constitution does not grant Congress or the Courts to spy, or to hire spies, or direct spies, or have anything to do with spies.