The scene was filmed in Nuevo Baztan a town south of Madrid. The scene of the men passing the entrance to the prison is at the rear of the Goyeneche Palace which is called Plaza de Fiestas.
This location has been used in several Euro-westerns including as for the prison in “The Hills Run Red” and the army headquarters in “The Genius”.
For a more detailed view of this site and other Spaghetti Western locations please visit my friend Captain Douglas’ excellent website: http://www.western-locations-spain.com
and Yoshi Yasuda’s location site: http://y-yasuda.net/film-location.htm
[Captain Douglas has dedicated and entire section of his website to “The Return of the Seven” with
behind the scenes photos and stories, highly recommended.]