Many tree path problems need two values: one for the global answer (path through node), one for recursion (path extending from node). The returned value is what the parent uses to extend its own path. The global variable tracks the overall best path found.
This pattern appears in diameter problems, longest paths, maximum path sums, and other tree improvement questions. Keep them separate. Confusing them is the most common mistake in path DP.