The rotations around axes appear to be commutative. If I perform a $180^{\circ}$ rotation around the $x$-axis and then another rotation around the $y$-axis, I obtain:
Rotation around the $x$-axis: $$x,\, y,\, z \Rightarrow x,\, -y,\, -z$$ Rotation around the $y$-axis: $$x,\, -y,\, -z \Rightarrow -x,\, -y,\, z$$ However, if I reverse the order and rotate $180^{\circ}$ around the $y$-axis first and then around the $x$-axis, I still get the same result:
Rotation around the $y$-axis: $$x,\, y,\, z \Rightarrow -x,\, y,\, -z$$ Rotation around the $x$-axis: $$-x,\, y,\, -z \Rightarrow -x,\, -y,\, z$$ As you can see, the composition of rotations is commutative. In quaternion algebra, quaternion multiplication is defined as the composition of rotations. But based on what we have seen above, it is not necessary for this multiplication to be non-commutative, as the composition of rotations in practice is not.
However, I have read that in order to maintain the consistent algebraic structure of quaternions, Hamilton formulated: $i^{2} = j^{2} = k^{2} = i j k = -1$
Where $i j k = -1$ precisely because multiplication should not be commutative. It is not clear to me why the non-commutativity of quaternion multiplication arises from this definition ($i j k = -1$), nor why this non-commutativity is necessary despite not being observed in practice. Is there something that I am missing or have not understood well? What led Hamilton to understand that $i j k = -1$?
Rotation
If you use the vector / quaternion $r$ as the axis of rotation, $\varphi$ as the rotation angle, $\mathrm{v}$ as the vector to be rotated and the rotated vector $\mathrm{v}_{\text{rotated}}$, then the formula applies: $$ \begin{align*} \mathrm{v}_{\text{rotated}} &= \mathrm{q} \cdot \mathrm{v} \cdot \overline{\mathrm{q}}\\ \mathrm{v}_{\text{rotated}} &= \left( \cos\left( \frac{\varphi}{2} \right) + \mathrm{u} \cdot \sin\left( \frac{\varphi}{2} \right) \right) \cdot \mathrm{v} \cdot \left( \cos\left( \frac{\varphi}{2} \right) - \mathrm{u} \cdot \sin\left( \frac{\varphi}{2} \right) \right)\\ \mathrm{v}_{\text{rotated}} &= \left( \cos\left( \frac{\varphi}{2} \right) + \frac{\mathrm{r}}{||\mathrm{r}||} \cdot \sin\left( \frac{\varphi}{2} \right) \right) \cdot \mathrm{v} \cdot \left( \cos\left( \frac{\varphi}{2} \right) - \frac{\mathrm{r}}{||\mathrm{r}||} \cdot \sin\left( \frac{\varphi}{2} \right) \right)\\ \end{align*} $$
However, this formula is only always true if $i \cdot j \cdot k = -1$ (Hemilton's definition). The important thing here is "always". If we only do rotations of $\varphi = g \cdot 180^{\circ} \wedge g \in \mathbb{Z}$ then it doesn't matter which axis we rotate around first, which is why you don't emphasize the importance of the in your examples see order (or the non-comutativity). The rotation around the $y$ axis with the formula:
$$ \begin{align*} x' \cdot i + y' \cdot j + z' \cdot k &= \left( \cos\left( \frac{180^{\circ}}{2} \right) + \sin\left( \frac{180^{\circ}}{2} \right) \cdot j \right) \cdot \left( x \cdot i + y \cdot j + z \cdot k \right) \cdot \left( \cos\left( \frac{180^{\circ}}{2} \right) - \sin\left( \frac{180^{\circ}}{2} \right) \cdot j \right)\\ x' \cdot i + y' \cdot j + z' \cdot k &= \left( \cos\left( 90^{\circ} \right) + \sin\left( 90^{\circ} \right) \cdot j \right) \cdot \left( x \cdot i + y \cdot j + z \cdot k \right) \cdot \left( \cos\left( 90^{\circ} \right) - \sin\left( 90^{\circ} \right) \cdot j \right)\\ x' \cdot i + y' \cdot j + z' \cdot k &= \left( 0 + 1 \cdot j \right) \cdot \left( x \cdot i + y \cdot j + z \cdot k \right) \cdot \left( 0 - 1 \cdot j \right)\\ x' \cdot i + y' \cdot j + z' \cdot k &= \left( x \cdot j \cdot i + y \cdot j \cdot j + z \cdot j \cdot k \right) \cdot \left( 0 - 1 \cdot j \right)\\ x' \cdot i + y' \cdot j + z' \cdot k &= \left( -x \cdot k - y + z \cdot i \right) \cdot \left( 0 - 1 \cdot j \right)\\ x' \cdot i + y' \cdot j + z' \cdot k &= \left( x \cdot k \cdot j + y \cdot j - z \cdot i \cdot j \right)\\ x' \cdot i + y' \cdot j + z' \cdot k &= \left( -x \cdot i + y \cdot j - z \cdot k \right)\\ x' \cdot i + y' \cdot j + z' \cdot k &= -x \cdot i + y \cdot j - z \cdot k\\ \end{align*} $$
However, the whole thing changes for all $\varphi \ne g \cdot 180^{\circ} \wedge g \in \mathbb{Z}$.
A plot of rotation of quternion $q = i + j + k$ by $45^{\circ}$ around $x$-axis first and $y$-axis second (pink points) and around $y$-axis first and $x$-axis second (purple points) where $q' =$ first rotation and $q'' =$ second rotation:
The red axis is the $\color{red}{x}$-axis, green axis is the $\color{green}{y}$-axis and blue axis is the $\color{blue}{z}$-axis. The green circle is the circle of the second rotation and the red one is the circle of the first rotation.
Other Definition
Carl Friedrich Gauß had the imaginary units of the quaternions with $i \circ j \circ k = + 1$ defined. With this we would get the "Gegenring" of the quaternion $\mathbb{Q} = \left( \mathbb{R}^{4},\, +,\, \cdot \right)$ aka $\mathbb{Q}^{op} = \left( \mathbb{R}^{4},\, +,\, \circ \right)$. It's still not commutative here, but here we have the $+1$.