Proof (homotopic maps descend on path components)
Let $H: X\times [0,1] \to Y$ be a homotopy from $f$ to $g$. For every $x\in X$, we obtain a path $H(x, \cdot):[0,1] \to Y$ from $f(x)$ to $g(x)$. This shows that $[f(x)] = [g(x)]\in π_0(Y)$.
Let $H: X\times [0,1] \to Y$ be a homotopy from $f$ to $g$. For every $x\in X$, we obtain a path $H(x, \cdot):[0,1] \to Y$ from $f(x)$ to $g(x)$. This shows that $[f(x)] = [g(x)]\in π_0(Y)$.