Spain’s outgoing Prime Minister Pedro Sanchez has resigned as leader of the Socialist Party after their election defeat.