Actually, what makes the numerator be the sum of only the values of a specific food is the use of GROUP BY, not the usage of "name" in the first SELECT. The part of "name" is just calling the columns that are going to be shown. You could obtain the exact same result without actually using "name" in the SELECT.
The numerator is the SUM of the values GROUPED BY name. The GROUP BY at the end is still part of the calculation, if you change it to GROUP BY id, for example, you get the percentage that represents a single item by itself.
The denominator is the subquery that is in parenthesis and is only the SUM of all.