$\newcommand{\BK}[3]{\left|{#1},{#2}\right\rangle_{#3}}
\newcommand{\BKB}[3]{\mathbf{\left|{#1},{#2}\right\rangle_{\boldsymbol{#3}}}}
\newcommand{\FR}[2]{{\textstyle \frac{#1}{#2}}}
\newcommand{\BoldExp}[2]{{#1}^{\boldsymbol{#2}}}
\newcommand{\CMRR}[2]
{ \begin{bmatrix}
#1 \\
#2
\end{bmatrix} }
\newcommand{\MM}[4]
{ \begin{bmatrix}
#1 & #2\\
#3 & #4
\end{bmatrix} }
\newcommand{\MMM}[9]
{ \begin{bmatrix}
#1 & #2 & #3 \\
#4 & #5 & #6 \\
#7 & #8 & #9 \\
\end{bmatrix} }
\newcommand{\CMRRRR}[4]
{ \begin{bmatrix}
#1 \\
#2 \\
#3 \\
#4
\end{bmatrix} }
\newcommand{\CMRRR}[3]
{ \begin{bmatrix}
#1 \\
#2 \\
#3
\end{bmatrix} }
\newcommand{\RMCC}[2]
{ \begin{bmatrix}
#1 & #2
\end{bmatrix} }
\newcommand{\RMCCC}[3]
{ \begin{bmatrix}
#1 & #2 & #3
\end{bmatrix} }
\newcommand{\RMCCCC}[4]
{ \begin{bmatrix}
#1 & #2 & #3 & #4
\end{bmatrix} }
\newcommand{\OSS}[1]
{\overset{\boldsymbol{\sim}}{#1}}
\newcommand{\BoldSub}[2]{{#1}_{\boldsymbol{#2}}}
\newcommand{\OSB}[1]
{\overset{\boldsymbol{-\!\!\!\!\!-}}{#1}}$
These pions are mesons, composite particles of a quark $\boldsymbol{\lbrace}\boldsymbol{u},\boldsymbol{d}\boldsymbol{\rbrace}$ and an antiquark $\boldsymbol{\lbrace}\OSB{\boldsymbol{u}},\overline{\boldsymbol{d}}\boldsymbol{\rbrace}$ :
\begin{equation}
\begin{array}{cccccccc}
&\boldsymbol{\lbrace}\boldsymbol{u},\boldsymbol{d}\boldsymbol{\rbrace} \!\!\!\!\!&\boldsymbol{\otimes}& \!\!\!\!\boldsymbol{\lbrace}\OSB{\boldsymbol{u}},\overline{\boldsymbol{d}}\boldsymbol{\rbrace} & \!\!\boldsymbol{=}\!\! &
\boldsymbol{\lbrace}\boldsymbol{\omega}\boldsymbol{\rbrace}& \!\!\!\!\boldsymbol{\oplus}\!\!&\boldsymbol{\lbrace}\BoldExp{\boldsymbol{\pi}}{-},\BoldExp{\boldsymbol{\pi}}{0},\BoldExp{\boldsymbol{\pi}}{+}\boldsymbol{\rbrace} & \\
& \boldsymbol{2}\!\!\!\!\! & \boldsymbol{\otimes} & \!\!\!\!\OSB{\boldsymbol{2}} & \!\!\boldsymbol{=}\!\!&\boldsymbol{1}&\!\!\!\!\boldsymbol{\oplus}\!\!&\boldsymbol{3}&
\end{array}
\tag{01}\label{eq01}
\end{equation}
\begin{align}
&\left\{ \boldsymbol{\omega} = \sqrt{\tfrac{1}{2}}\left(\boldsymbol{u}\OSB{\boldsymbol{u}}+\boldsymbol{d}\overline{\boldsymbol{d}} \right)\hphantom{=\,}\right\} \quad \,\text{the singlet }\boldsymbol{1}
\tag{02.1}\label{eq02.1}\\
&\left.
\begin{cases}
\BoldExp{\boldsymbol{\pi}}{-} =\boldsymbol{d}\OSB{\boldsymbol{u}} \\
\BoldExp{\boldsymbol{\pi}}{0} =\sqrt{\tfrac{1}{2}}\left(\boldsymbol{u}\OSB{\boldsymbol{u}}-\boldsymbol{d}\overline{\boldsymbol{d}} \right)\\
\BoldExp{\boldsymbol{\pi}}{+} =\boldsymbol{u}\overline{\boldsymbol{d}}
\end{cases}\right\}\quad \text{the triplet }\boldsymbol{3}
\tag{02.2}\label{eq02.2}
\end{align}
The subspaces $\;\boldsymbol{1},\boldsymbol{3}\;$ are invariant under the isospin group $\;SU(2)$.
EDIT
responds to a comment by the OP owner :
This explanation is fine. But I still have a puzzlement. While the three pions ($\pi^{-}, \pi^{0}, \pi^{+}$) have an $SU(2)$ symmetry, why do the three quarks ($u,d,s$) have an $SU(3)$ [not $SU(2)$] symmetry? More generally, given three similar particles, how do we know whether they have an $SU(2)$ symmetry or an $SU(3)$ symmetry?
We must not confuse the number $\;n\;$ of the symmetry group $\;SU(n)\;$ with the number $\;m\;$ of the resulting $\;m-$plets (singlets,doublets,triplets,...nonets, etc).
In the following three examples the number $\;n\;$ of the symmetry group $\;SU(n)\;$ is the number of the $\;n\;$ independent $\;n-$dimensional systems we put together to build a composite system.
$\color{blue}{\textbf{Example A :}}$ If we put together a particle $\;\alpha\;$ of spin angular momentum $\;j_{\alpha}=\frac12\;$ with a particle $\;\beta\;$ of spin angular momentum $\;j_{\beta}=\frac12\;$ then the resulting multiplets is a singlet of angular momentum $\;j_{1}=0\;$ and a triplet of angular momentum $\;j_{2}=1\;$
\begin{equation}
\boldsymbol{2}\boldsymbol{\otimes}\boldsymbol{2}=\boldsymbol{1}\boldsymbol{\oplus}\boldsymbol{3}
\tag{ed-01}\label{eqed-01}
\end{equation}
Now let apply the following $\;SU(2)\;$ transformations to the systems $\;\alpha,\beta\;$ (particles) respectively
\begin{align}
^{\bf 2}U_{\bf \alpha} & =
\MM{\hphantom{\boldsymbol{-}}g_{\bf \alpha}}{h_{\bf \alpha}}{\vphantom{h^{\boldsymbol{*}}_{\bf \beta}}\boldsymbol{-}h^{\boldsymbol{*}}_{\bf \alpha}}{g^{\boldsymbol{*}}_{\bf \alpha}}_{\bf a}
\,,\quad
g_{\bf \alpha}g^{\boldsymbol{*}}_{\bf \alpha}\boldsymbol{+}h_{\bf \alpha}h^{\boldsymbol{*}}_{\bf \alpha}=1
\tag{ed-02a}\label{eqed-02a}\\
^{\bf 2}U_{\bf \beta} & =
\MM{\hphantom{\boldsymbol{-}}g_{\bf \beta}}{h_{\bf \beta}}{\boldsymbol{-}h^{\boldsymbol{*}}_{\bf \beta}}{g^{\boldsymbol{*}}_{\bf \beta}}_{\bf b}
\,,\quad
g_{\bf \beta}g^{\boldsymbol{*}}_{\bf \beta}\boldsymbol{+}h_{\bf \beta}h^{\boldsymbol{*}}_{\bf \beta}=1
\tag{ed-02b}\label{eqed-02b}
\end{align}
In the composite system this is a $\;SU(4)\;$ transformation, the product of the two ones above
\begin{equation}
^{\bf 4}U_{ f} = \left(^{\bf 2}U_{\bf \alpha}\right)\boldsymbol{\otimes}\left(^{\bf 2}U_{\bf \beta}\right)
=
\MM{\hphantom{\boldsymbol{-}}g_{\bf \alpha}}{h_{\bf \alpha}}{\vphantom{h^{\boldsymbol{*}}_{\bf \beta}}\boldsymbol{-}h^{\boldsymbol{*}}_{\bf \alpha}}{g^{\boldsymbol{*}}_{\bf \alpha}}_{\bf a}\!\!\!
\boldsymbol{\otimes}
\MM{\hphantom{\boldsymbol{-}}g_{\bf \beta}}{h_{\bf \beta}}{\boldsymbol{-}h^{\boldsymbol{*}}_{\bf \beta}}{g^{\boldsymbol{*}}_{\bf \beta}}_{\bf b}\!\!\!
=
\begin{bmatrix}
\hphantom{\boldsymbol{-}}g_{\bf \alpha}g_{\bf \beta} & \hphantom{\boldsymbol{-}}g_{\bf \alpha}h_{\bf \beta} & \hphantom{\boldsymbol{-}}h_{\bf \alpha}g_{\bf \beta} & h_{\bf \alpha}h_{\bf \beta} \\
\boldsymbol{-}g_{\bf \alpha}h^{\boldsymbol{*}}_{\bf \beta} & \hphantom{\boldsymbol{-}}g_{\bf \alpha}g^{\boldsymbol{*}}_{\bf \beta} & \boldsymbol{-}h_{\bf \alpha}h^{\boldsymbol{*}}_{\bf \beta} & h_{\bf \alpha}g^{\boldsymbol{*}}_{\bf \beta} \\
\boldsymbol{-}h^{\boldsymbol{*}}_{\bf \alpha}g_{\bf \beta} & \boldsymbol{-}h^{\boldsymbol{*}}_{\bf \alpha}h_{\bf \beta} & \hphantom{\boldsymbol{-}}g^{\boldsymbol{*}}_{\bf \alpha}g_{\bf \beta} & g^{\boldsymbol{*}}_{\bf \alpha}h_{\bf \beta} \\
\hphantom{\boldsymbol{-}}h^{\boldsymbol{*}}_{\bf \alpha}h^{\boldsymbol{*}}_{\bf \beta} & \boldsymbol{-}h^{\boldsymbol{*}}_{\bf \alpha}g^{\boldsymbol{*}}_{\bf \beta} & \boldsymbol{-}g^{\boldsymbol{*}}_{\bf \alpha}h^{\boldsymbol{*}}_{\bf \beta} & g^{\boldsymbol{*}}_{\bf \alpha}g^{\boldsymbol{*}}_{\bf \beta}
\end{bmatrix}_{\bf e}
\tag{ed-03}\label{eqed-03}
\end{equation}
But the $\;SU(2)\;$ transformations in \eqref{eqed-02a},\eqref{eqed-02b} represent rotations in the real space $\;\mathbb{R}^{3}\;$ wherein both particles live, so they must be identical (we would not rotate one system differently from the other)
\begin{equation}
^{\bf 2}U_{\bf \alpha} =\,^{\bf 2}U_{\bf \beta}=\,
^{\bf 2}U =
\MM{\:\:g}{h}{\boldsymbol{-}h^{\boldsymbol{*}}}{\:\:g^{\boldsymbol{*}}}
\,,\quad
gg^{\boldsymbol{*}}\boldsymbol{+}hh^{\boldsymbol{*}}=1
\tag{ed-04}\label{eqed-04}
\end{equation}
so that \eqref{eqed-03} yields
\begin{equation}
^{\bf 4}U_{ f} = \left(^{\bf 2}U_{\bf \alpha}\right)\boldsymbol{\otimes}\left(^{\bf 2}U_{\bf \beta}\right)
=\left(^{\bf 2}U\right)^{\boldsymbol{\otimes}2}
=
\begin{bmatrix}
\:g^{2} & \:\:gh & \:hg & \!\!\!h^{2} \\
\boldsymbol{-}gh^{\boldsymbol{*}} & \hphantom{\boldsymbol{-}}gg^{\boldsymbol{*}} & \boldsymbol{-}hh^{\boldsymbol{*}} & hg^{\boldsymbol{*}}\\
\boldsymbol{-}h^{\boldsymbol{*}}g & \,\boldsymbol{-}h^{\boldsymbol{*}}h & \hphantom{\boldsymbol{-}}g^{\boldsymbol{*}}g & g^{\boldsymbol{*}}h \\
\hphantom{\boldsymbol{-}}h^{\boldsymbol{*}2} & \:\:\boldsymbol{-}h^{\boldsymbol{*}}g^{\boldsymbol{*}} & \:\:\boldsymbol{-}g^{\boldsymbol{*}}h^{\boldsymbol{*}} & g^{\boldsymbol{*}2}
\end{bmatrix}_{\bf e}
\tag{ed-05}\label{eqed-05}
\end{equation}
This matrix expressed in the basis of the irreducible direct sum \eqref{eqed-01} is
\begin{equation}
^{\bf 4}\OSS{U}_{ f}=
\begin{bmatrix}
\begin{array}{c|ccc}
\:\: 1 \:\: &\rule [0ex]{20pt}{0.0ex}&\rule [-2.5ex]{0pt}{6.0ex} \rule [0ex]{16pt}{0ex}& \rule [0ex]{16pt}{0ex}\\
\hline
\rule [-3ex]{0pt}{6ex}&g^{2}& \sqrt{2} g h & h^{2} \\
\rule [-3ex]{0pt}{6ex}& -\sqrt{2} g h^{\boldsymbol{*}} & \left(g g^{\boldsymbol{*}}-h h^{\boldsymbol{*}}\right) & \sqrt{2} g^{\boldsymbol{*}} h \\
\rule [-3ex]{0pt}{6ex}& \left(h^{\boldsymbol{*}}\right)^{2} & - \sqrt{2}g^{\boldsymbol{*}} h^{\boldsymbol{*}} & \left(g^{\boldsymbol{*}}\right)^{2}
\end{array}
\end{bmatrix}_{\:\mathbf{f}}
=
\begin{bmatrix}
\begin{array}{c|ccc}
^{\mathbf{1}}U_{\boldsymbol{\left[1\right]}}&\rule [0ex]{20pt}{0.0ex}&\rule [-2.5ex]{0pt}{6.0ex} \rule [0ex]{16pt}{0ex}& \rule [0ex]{16pt}{0ex}\\
\hline
\rule [-3ex]{0pt}{6ex}&\rule [0.0ex]{50pt}{0.0ex}& \rule [0.0ex]{50pt}{0.0ex} &\rule [0.0ex]{50pt}{0.0ex}\\
\rule [-3ex]{0pt}{6ex}& & ^{\mathbf{3}}U_{\boldsymbol{\left[2\right]}} & \\
\rule [-3ex]{0pt}{6ex}& & &
\end{array}
\end{bmatrix}_{\:\mathbf{f}}
\tag{ed-06}\label{eqed-06}
\end{equation}
where $\:^{\mathbf{1}}U_{\boldsymbol{\left[1\right]}}\:$ and $\:^{\mathbf{3}}U_{\boldsymbol{\left[2\right]}}\:$ are special unitary matrices in the spaces of the singlet and of the triplet respectively given by
\begin{equation}
^{\mathbf{1}}U_{\boldsymbol{\left[1\right]}}=
\begin{bmatrix}
1
\end{bmatrix}
\quad \in SU(1)\equiv \{1\}
\tag{ed-07}\label{eqed-07}
\end{equation}
\begin{equation}
^{\mathbf{3}}U_{\boldsymbol{\left[2\right]}}=
\begin{bmatrix}
g^{2}& \sqrt{2} g h & h^{2} \rule [-3ex]{0pt}{6ex}\\
-\sqrt{2} g h^{\boldsymbol{*}} & \left(g g^{\boldsymbol{*}}-h h^{\boldsymbol{*}}\right) & \sqrt{2} g^{\boldsymbol{*}} h \rule [-3ex]{0pt}{6ex}\\
\left(h^{\boldsymbol{*}}\right)^{2} & - \sqrt{2}g^{\boldsymbol{*}} h^{\boldsymbol{*}} & \left(g^{\boldsymbol{*}}\right)^{2} \rule [-3ex]{0pt}{6ex}
\end{bmatrix}
\quad \in SU(3)
\tag{ed-08}\label{eqed-08}
\end{equation}
So if we apply the $\;SU(2)\;$ transformation $\:^{\bf 2}U\:$ of \eqref{eqed-04} on both spaces in the product of the lhs of \eqref{eqed-01} then the spaces of the terms of the direct sum of the rhs side of the same equation remain invariant, the singlet \eqref{eq02.1} invariant under $\;SU(1)\;$ (more exactly unchanged) and the triplet \eqref{eq02.2} transformed under $\;SU(3)\;$ remaining in its invariant space.
We say that the symmetry group is $\;SU(2)$, NOT $\;SU(1)\;$ or $\;SU(3)\;$ of the resulting multiplets.
Reference link : Total spin of two spin-1/2 particles.
$\color{blue}{\textbf{Example B :}}$ The quark model of baryons consisting of three quarks. So, suppose we know the existence of three quarks only : $\boldsymbol{u}$, $\boldsymbol{d}$ and $\boldsymbol{s}$. Under full symmetry (the same mass) these are the basic states, let
\begin{equation}
\boldsymbol{u}=
\begin{bmatrix}
1\\
0\\
0
\end{bmatrix}
\qquad
\boldsymbol{d}=
\begin{bmatrix}
0\\
1\\
0
\end{bmatrix}
\qquad
\boldsymbol{s}=
\begin{bmatrix}
0\\
0\\
1
\end{bmatrix}
\tag{ed-09}\label{eqed-09}
\end{equation}
of a 3-dimensional complex Hilbert space of quarks, say $\mathbf{Q}\equiv \mathbb{C}^{\boldsymbol{3}}$. A quark $\boldsymbol{\xi} \in \mathbf{Q}$ is expressed in terms of these basic states as
\begin{equation}
\boldsymbol{\xi}=\xi_1\boldsymbol{u}+\xi_2\boldsymbol{d}+\xi_3\boldsymbol{s}=
\begin{bmatrix}
\xi_1\\
\xi_2\\
\xi_3
\end{bmatrix}
\qquad \xi_1,\xi_2,\xi_3 \in \mathbb{C}
\tag{ed-10}\label{eqed-10}
\end{equation}
Let take 2 more quarks in order to construct baryons from 3 quarks
\begin{equation}
\boldsymbol{\eta}=\eta_1\boldsymbol{u}+\eta_2\boldsymbol{d}+\eta_3\boldsymbol{s}=
\begin{bmatrix}
\eta_1\\
\eta_2\\
\eta_3
\end{bmatrix} \:,
\qquad
\boldsymbol{\zeta}=\zeta_1\boldsymbol{u}+\zeta_2\boldsymbol{d}+\zeta_3\boldsymbol{s}=
\begin{bmatrix}
\zeta_1\\
\zeta_2\\
\zeta_3
\end{bmatrix}
\tag{ed-11}\label{eqed-11}
\end{equation}
A baryon state $\:T\:$ in the product space
\begin{equation}
\mathbf{B}=\boldsymbol{3}\boldsymbol{\otimes}\boldsymbol{3}\boldsymbol{\otimes}\boldsymbol{3}=\mathbf{Q}\boldsymbol{\otimes}\mathbf{Q}\boldsymbol{\otimes}\mathbf{Q}\equiv \mathbb{C}^{\boldsymbol{3}}\boldsymbol{\otimes}\mathbb{C}^{\boldsymbol{3}}\boldsymbol{\otimes}\mathbb{C}^{\boldsymbol{3}}=\mathbb{C}^{\boldsymbol{27}}
\tag{ed-12}\label{eqed-12}
\end{equation}
is the product of the states of above 3 quarks
\begin{equation} T=\boldsymbol{\xi}\boldsymbol{\otimes}\boldsymbol{\eta}\boldsymbol{\otimes}\boldsymbol{\zeta}
\tag{ed-13}\label{eqed-13}
\end{equation}
The final result of a full analysis is
\begin{equation}
\boldsymbol{3}\boldsymbol{\otimes}\boldsymbol{3}\boldsymbol{\otimes}\boldsymbol{3}=
\boldsymbol{1}\boldsymbol{\oplus}\boldsymbol{10}\boldsymbol{\oplus}
\boldsymbol{8}^{\boldsymbol{\prime}}\boldsymbol{\oplus}\boldsymbol{8}
\tag{ed-14}\label{eqed-14}
\end{equation}
that is the space of states of a baryon is the direct sum of a singlet $\;\boldsymbol{1}$, a decuplet $\;\boldsymbol{10}$, a mixed symmetric octet $\;\boldsymbol{8'}$ and a mixed anti-symmetric octet $\;\boldsymbol{8}$.
Now applying a $\;SU(3)\;$ transformation $\;^{\bf 3}U\;$ on the 3-dimensional space $\mathbf{Q}\equiv \mathbb{C}^{\boldsymbol{3}}$ results in a $\;SU(27)\;$ transformation $\;^{\bf 27}U\;$ on the 27-dimensional space $\;\mathbf{B}\;$ of equation \eqref{eqed-12}
\begin{equation}
^{\bf 27}U = \left(^{\bf 3}U\right)\boldsymbol{\otimes}\left(^{\bf 3}U\right)\boldsymbol{\otimes}\left(^{\bf 3}U\right)
=\left(^{\bf 3}U\right)^{\boldsymbol{\otimes}3}
\tag{ed-15}\label{eqed-15}
\end{equation}
The space of each $\;m-$plet remains invariant and a state in this $\;m-$plet is transformed under a $\;SU(m)\;$ transformation, where $\;m=1,10,8,8$. But
We say that the symmetry group is $\;SU(3)$, NOT $\;SU(1)\;$ or $\;SU(10)\;$ or $\;SU(8)\;$ of the resulting multiplets.
Reference link : Symmetry in terms of matrices.