The US president criticised the Spanish government after it blocked the US from using its bases during the attack on Iran.