Every path in a tree passes through some "highest" node, the node closest to the root that lies on the path. At this node, the path connects two downward branches.
So for each node, you can ask: what's the longest path that passes through me? That path goes down into one child's subtree, back up through me, and down into another child's subtree. The diameter is the maximum of these "path through node" values across all nodes.