As exhibition opens in Madrid, new research shows how Picasso was inspired by church paintings to create Spanish Civil War rallying cry