This question is taken from Mukres' Topology (exercise 51.2.b). This site provides the following answer:
All “closed” segments of a path are homotopic to the whole path. Since $Y$ is path connected, for any two paths we can connect the final point of the first one with the initial point of the second one by a path to form the product of three paths, in which the two given paths are “closed” segments. Given the idea, it can be shown formally, of course.
Why does this prove that all paths in $Y$ are homotopic? For any two paths to be pasted to a new path in the same space does not prove that any two paths are homotopic, right?
My attempt at this problem is the following:
Take any two paths $f, f':[0,1] \rightarrow Y$, then $F(t,x) := (1-t)f(x) + tf'(x)$ is continuous and has $F(0,x) = f(x)$ and $F(1, x)=f'(x)$, thus $F$ is a homotopy between any two paths in $Y$ and thus all paths in $Y$ are homotopic.
However, I think that I am wrong since this doesn't use path-connectedness of $Y$.
The idea is this: Given $f,f':[0,1]\to Y$, there is a path $g:[0,1]\to Y$ with $g(0)=f(1)$ and $g(1)=f'(0)$. Then consider the path $f*g*f'$ (or $f'*g*f$, I forget the notation of Munkres, but the path that starts at $f(0)$ and ends at $f'(1)$. Then $f$ is homotopic to $f*g*f'$, which is in turn homotopic to $f'$ (this is because, as stated in the solution, any path is homotopic to a closed segment of that path).