A National Court judge said on Wednesday there was no evidence that the suspects had jihadist links, El Mundo reports.
The case against the men collapsed after a police informant was found to have fabricated claims that the men had been radicalised by an Islamist extremist.
Spanish police now believe that videos found at the home of a suspected jihadist, showing armed men in front of a central Madrid square, were a montage put together by their informant.
A police informant dubbed "Lolo" contacted Spain's CNI intelligence agency last July but the agency concluded the information he provided them with was a montage, El Mundo reported.
The informant, who was paid monthly by the police and had to supply "extraordinary" information to get a bonus, alerted authorities about the existence of a jihadist cell that was read to carry out attacks and offered the videos as proof, it added.
After the intelligence agency showed little interest, he turned to police in Madrid who opened an investigation with the aid of "Lolo" and on December 30th arrested two Spanish men who appeared in the videos.
The interior ministry said at the time that the two men, Edrissa Ceesay Sanuwo and Samir Sennouni Mouh, had been detained for "glorifying terrorism" and "possession of war weapons and ammunition"
The authorities said the two men held an AK-47 rifle in several videos which featured Islamic State symbols and a picture of Puerta del Sol, a major square in central Madrid.
But later the two men said it was "Lolo" who came up with the ideas for the videos and put them online.
Almost 200 alleged jihadists have been detained since 2015, when Spain increased its terror alert to category four on a five-point scale.
Spain has been mentioned on extremist websites as a possible attack target for historical reasons, given much of its territory was under Muslim rule from 711 to 1492.
But unlike France or Belgium, the country is less exposed to the risk of return of radicalised nationals who went to fight abroad and plan to commit extremist acts on home soil.
Only around 200 Spaniards are estimated to have gone abroad to fight, compared to thousands from nearby France and Belgium.