How does a spinning electron produce a magnetic field?

An electron is not a spinning ball of charge and the intrinsic spin of particles cannot be understood in such terms. Not only is it difficult to make sense of what it means for a pointlike particle to spin, but also when treating the electron as a spinning ball of charge one finds a value of the ratio between the magnetic moment and the angular momentum that is a factor $2$ too small.

To understand why a rotating charged ball generates a magnetic field, note that every charge on the ball will move in a circle, so there is in fact a current, and that current will generate a magnetic field.

There is no classical analogue to visualise what spin is. We found out from experiments that particles have an intrinsic property which we named spin which produces a magnetic moment. You cannot visualise it since fundamental particles are zero-dimensional points in space so the term "spinning around its axis" makes no physical sense.

Its a strictly observational effect which fits well with our mathematical models and explains a great range of phenomena in nature.

Lets take the rotating "spherical ball" analogy seriously (actually a torus below).

The electron is modeled as a tiny stationnary torus rotating at an angular velocity $\omega$ around the symmetry axis passing through its center of mass. The material on the torus is moving at velocity $v = \omega \, r \le c$. The classical spin angular momentum is then $S = r \, p$ where $p = \gamma \, m_0 v$ is the linear momentum of the rotating material on the torus. $\gamma = 1/\sqrt{1 - v^2 /c^2}$ is the relativistic factor. You get the spin angular momentum \begin{equation}\tag{1} S = \frac{m_0 \, \omega \, r^2}{\sqrt{1 - \frac{\omega^2 r^2}{c^2}}}. \end{equation} Now, lets take the limit $r \rightarrow 0$ (spinning point-like electron, or a dot spinning on itself!). Is it possible to apply that limit in such a way that equ(1) above gives some constant ? Of course, the trivial solution is $S = 0$ is we consider $\omega$ as an independent variable. But there's also a non-trivial solution if we also take the limit $\omega \rightarrow \infty$ in such a way as $v = \omega \, r \rightarrow c$ (so the relativistic factor goes to infinity). Considering $S$ as a non-trivial constant, you get the spinning angular velocity as a function of the torus radius : \begin{align} \omega &= \frac{S/m_0}{r \, \sqrt{r^2 + (S / m_0 c)^2}}, \tag{2} \\[12pt] v &= \omega \, r = \frac{S/m_0}{r^2 + (S / m_0 c)^2}. \tag{3} \end{align} The limit $r \rightarrow 0$ then gives $\omega \rightarrow \infty$, $v \rightarrow c$ (and $\gamma \rightarrow \infty$), and $S$ a non-trivial constant !

This is the same kind of non-trivial relativistic solution that you get for a massless particle : $m_0 \rightarrow 0$, using the energy and linear momentum : \begin{align} E &= \gamma \, m_0 c^2, \tag{4} \\[12pt] p &= \gamma \, m_0 v, \tag{5} \\[12pt] v &\equiv \frac{p \, c^2}{E}, \tag{6} \\[12pt] E^2 &= p^2 c^2 + m_0^2 \, c^4. \tag{7} \end{align} The limit $m_0 \rightarrow 0$ trivially gives $E = 0$ and $p = 0$ (so the massless particle doesn't exists!). But you also have the non-trivial solution $m_0 \rightarrow 0$ and $v \rightarrow c$ such that $\gamma \, m_0$ remains finite and $E = p \, c$ is a finite non-trivial constant.

According to the torus model above (or a sphere, or any other shape), we can model an electron as a small ring of charges rotating in such a way that it produces a magnetic field, even under the limit $r \rightarrow 0$ (spinning dot model!). This is possible because of relativity (i.e. the gamma factor).

The ring model above has a fatal defect : total energy $E = \gamma \, m_0 c^2$ diverges, if $m_0$ is a simple constant, while $\gamma \rightarrow \infty$! For the torus, we would like to get $E = \gamma \, m_0 c^2 = m_e c^2$ (a finite non-trivial constant) for a tiny torus. This imposes \begin{equation}\tag{8} S = \gamma \, m_0 \, \omega \, r^2 \equiv m_e \omega \, r^2. \end{equation} Keeping $S$ a constant implies \begin{align} \omega &= \frac{S/m_e}{r^2}, \tag{9} \\[12pt] v = \omega \, r &= \frac{S}{m_e \, r}. \tag{10} \end{align} The minimum radius cannot be 0 : \begin{equation}\tag{11} r_{\text{min}} = \frac{S}{m_e c} = \frac{\hbar}{2 m_e c}, \end{equation} which is about the Compton length. Under this limit (i.e. $r \rightarrow r_{\text{min}}$), we get $v \rightarrow c$, $\gamma \rightarrow \infty$, $m_0 \rightarrow 0$, while $E \rightarrow m_e c^2$ and $S = \frac{\hbar}{2}$. According to this rotating massless ring model, the electron cannot be turned into a point particle.