The five were among 15 suspected members of a group called the Coordinated Anarchist Groups, who were detained on Monday in raids across Spain.
Police believe three of the five jailed suspects are the leaders of the organisation in Madrid, Barcelona and the northern city of Palencia.
The five are accused of membership in a terrorist organisation and are suspected of damaging 114 bank machines.
The authorities also suspect they were involved in the February 2013 attempted bombing of the Almudena Cathedral, a tourist attraction in the heart of Madrid next to the city's royal palace.
A priest found the home-made bomb -- made up of a detonator, gunpowder and gas canister filled with nails -- in a bin bag. He contacted the police, who defused the device.
The authorities are also looking into their possible role in the setting off of a small bomb at a Baroque-era church in the northeastern city of Zaragoza in October 2013.
The blast caused no injuries or damage to the church.
The court released 10 other suspected members of the anarchist group who had also been detained on Monday, but ordered them to regularly report to the police while the investigation continues.