If you remember back in Bahrain in the last stint, both lewis and Alonso were extremely quick on the hard compounds as compared to Massa on the softs... at the end of the race there was a discussion about why Mclaren didnt bolt them on earlier if they worked so well. Apparently they didnt want to risk the car balance or something and so they just stuck to their pre race game plan.
Here in spain they were in almost the same position. Massa leading, lewis in pursuit and Alonso training with body work damage. So instead of following exactly what they did in Bahrain, Alonso and the team chose to do something different because lets face it... what did they have to lose? they were comfortably 3rd with kimi out and had no chance of catching Massa. By bolting on the harder compound in the mid stint, they were trying to establish two things. Would it help Alonso's poor pace and if it does work, they'd stop hamilton slightly early and do the same.
They based all that thinking on the fact that in free practice on friday, both Mclarens were very very fast on the hard tyres, most other teams were completely at sea, despite the fact that they had all tested there withing the last week. Unfortunately for Alonso they track conditions had changed since friday and the harder tyre brought him no significant advantage.