That last step _looks_ like it couldn't possibly work. But with a dataset array it does, and here's why:
grps is a subset of d.var, and so it is a cell array of strings. gmeans is a dataset array with observation names 'A', 'B', and 'C' -- you can see those at the left margin of the display. And so gmeans.mean_var(grps) indexes into the "mean_var" variable by matching up what's in grps with the observation names that "mean_var" inherits from the dataset array it lives in.