What if the tree is not binary? What if a node has children? You could modify the previous approach, but there is a simpler algorithm that works for any tree: Double BFS. The idea:
Start from any node and find the furthest node from it.
From that node, find the furthest node again.
The distance in step is the diameter. This works because the furthest node from any starting point is always one endpoint of the diameter.