Every path in a tree has a turning point where it changes from going down one subtree to going down another. For each node, the longest path through it is: left subtree height + right subtree height.
The diameter is the maximum of that sum across all nodes. This fits the Tree DP pattern: compute a value per node, combine child results, update a global answer. The height function does double duty by returning height to the parent while updating the global diameter.