Pedro Sanchez resigned as leader of Spain's Socialist Party after losing the general election to the conservative People's Party, setting up a legislative transition.