Ontogenetic niche shifts and flexible behaviour in size-structured populations