I tried to check $\pi_0$ is a functor form $\textbf{Top}$ to $\textbf{Set}$
$$\require{AMScd}
\begin{CD}
X @. \hspace{2em} \pi_0{X}\\
@V{f}VV @V{\pi_0f}VV \\
Y @. \hspace{2em} \pi_0{Y}\\
@V{g}VV \hspace{2em} @V{\pi_0g}VV \\
Z @. \hspace{2em} \pi_0{Z}\\
\end{CD}$$
$\pi_0X$ is the path-connected components of $X$, we define $\pi_0f$, below I first check it is well-defined.
For a $A \in \pi_0(X)$, (First show $A$ is path connected. All elements of $A$ are path-connected wrt $X$, i.e. For any points $x$, $y$, there exists a path $\gamma$ from $I$ to $X$, now I need to show For any points $x$, $y$, there exists a path from $I$ to $A$, define $\gamma' (a)=\gamma(a), \forall a \in I$, so we have $i (\text{inclusion map} )\circ \gamma' = \gamma$, then $\gamma'$ is continuous by the universal property of subspace topology? )
$$
\begin{array}{ccc}
{} & {} & X \\
{} & \overset{\gamma}{\nearrow} & \uparrow i \\
I & \underset{\gamma'}{\to} & A
\end{array}
$$
$f(A)$ is path-connected, by similar arguments as above (Here we have $k$ continuous, so $i\circ k$ is continuous), all the points of $f(A)$ are path-connected in $Y$, so there exists a unique component containing $f(A)$.
$$
\begin{array}{ccc}
{} & {} & Y \\
{} & \overset{i \circ k}{\nearrow} & \uparrow i \\
I & \underset{k}{\to} & f(A)
\end{array}
$$
I always do this tedious work (switching between subspace and whole space), can we skip it?
Now I check it is a functor,
$\pi_0(g \circ f)= \pi_0g \circ \pi_0f$
Pick $A \in \pi_0X$, suppose $B$ covers $f(A)$, and $C$ covers $g(B)$, then
$\pi_0g \circ \pi_0f (A)= \pi_0g(B)=C$
$f(A) \subset B$, so $gf(A) \subset g(B) \subset C$
so $\pi_0(g \circ f)(A)=C$ (Is it right?)
Best Answer
For the first part, to prove that $A$ is path-connected, take $z \in A \subset X$ such that $A$ is the path-connected component of $z$ in $X$ (i.e. $A$ is the equivalence class of $z$ under the path-connected equivalence relation). You need to show that for every $x,y \in A$, there exists a continuous map $\gamma' : I \to A$ such that $\gamma'(0) = x$ and $\gamma'(1) = y$ (here $I = [0,1]$) or, in other words, that for every $t \in I$, there exists a path between $\gamma'(t)$ and $z$. This is not what you did (you already assume that $\gamma'$ takes its values in $A$).
For the rest of the proof, it seems good to me. You also have to prove that $\pi_0(\text{id}_X) = \text{id}_{\pi_0(X)}$.
EDIT : I'm using this definition of a path-connected component :
I know that in some books, a path-connected component is just a maximal subspace of $X$ (for the inclusion) that is path-connected and, of course with this definition, the first step of your proof is trivial. Now to see the equivalence between these two definitions, you can show that the class of an element $x \in X$ (under the relation $\sim$) is just the union over all the path-connected subspaces of $X$ containg $x$, i.e. $$\text{cl}(x) = \bigcup_{C \subset X, ~x \in C} C, ~~~~C \text{ is path-connected}$$ Using the fact that a family $(V_i)_{i \in I}$ of path-connected subspaces of $X$ veryfing $\cap_{i \in I} V_i \neq \emptyset$ is such that $\cup_{i \in I} V_i \subset X$ is path-connected, the above description of cl$(x)$ shows that it is the maximal subspace of $X$ containing $x$ that is path-connected (and of course this is a maximal subspace of $X$ for the property «being path-connected»), and it establishes the equivalence of the two definitions. In particular, every path-connected component of a topological space $X$ is itself path-connected.