The proof in my lecture notes starts as such:
Let $T$ be a finite tree on at least $2$ vertices. Consider a path $P = xe_1x_1e_2...y$ of maximum length in $T$. This path begins with a vertex $x$, and ends with a different vertex $y$. Assume that one of $x,y$ (w.l.o.g. $x$) has degree at least $2$. Thus $x$ has a neighbour $w$ different from $x_1$. If $w$ is not contained in $P$, then the path going from $w$ to $x$ and then via $P$ to $y$ is strictly longer than $P$, contradicting the maximality of $P$. Hence, $w$ is in $P$.
So far so good. Now comes the part I don't understand:
but then $T$ contains a cycle: Starting at $x$, follow along $P$ until $w$, then go back to $x$ via the edge $\{x,w\}$.
I don't understand how this can be a cycle. When you "start at $x$, follow along $P$ until $w$", don't you walk along the edge $\{x,w\}$?
.
You have drawn the picture incorrectly. The vertex $w$ lies on the path $P$ and does not coincide with $x_1$, so moving along $P$ until you meet $w$ you will not traverse the edge $xw$. This really means that your graph contains a cycle. Here is the correct picture (in red the path $P$ is shown):