This problem uses sum as the combine function. You add contributions from children when computing down[v]. You add parent and sibling contributions when computing up[v]. The +size[u] term appears when you move down an edge because every node in subtree is now step farther from the current node.
This pattern shows up in many distance-sum problems. This pattern applies to any problem where you sum distances or counts over all nodes. Rerooting converts what would be brute force into linear solution.