[Answer completely rewritten.]
Indeed we have:
$\DeclareMathOperator\so{\mathfrak{so}}$Fix $n\ge 4$ and $p,q\ge 0$ with $p+q=n$; write $r=\min(p,q)$. Then the minimal codimension for the centralizer of a nonzero element in $\so(p,q)$ is $2n-6$ if $r\ge 2$ and $2n-4$ if $r\in\{0,1\}$.
(The cases $n=2,3$ being straightforward: in this case $2n-4$ is the minimal codimension.)
To prove the result let's consider separately $r\ge 2$ and $r\le 1$. First we have
For every nondegenerate quadratic form $q$ in dimension $n\ge 4$ over a field $K$ of characteristic zero, the codimension of the centralizer of every nonzero element of $\mathfrak{so}(q)$ is $\ge 2n-6$, which moreover is achieved if $r\ge 2$.
First let us check that it is achieved if $r\ge 2$. Indeed, we then choose a basis $(e_1,\dots,e_n)$ for which the bilinear form $b$ associated to $q$ satisfies $b(e_1,e_n)=b(e_2,e_{n-1})=1$, and such that the subspaces of bases $(e_1,e_2,e_{n-1},e_n)$ and $(e_3,\dots,e_{n-2})$ are orthogonal. Decomposing matrices with blocks of size $1+1+(n-4)+1+1$, consider the matrix $$g=\begin{pmatrix}0 & 0 & \quad 0\quad & 1 & 0\\ 0 & 0 & 0 & 0 & -1 \\ \\0 & 0 & 0 & 0 & 0 \\ \\ 0 & 0 & 0 & 0 & 0\\ 0 & 0 & 0 & 0 & 0\end{pmatrix}.$$ Then its centralizer in $\so(q)$ has codimension $2n-6$. Indeed, the latter verification can be performed over an algebraic closure, in which case we can suppose furthermore that $b(e_i,e_j)=\delta_{i+j,n+1}$. So $\so(q)$ consists of matrices that are skew-symmetric with respect to the antidiagonal. In such a basis, the centralizer of $g$ consists of those matrices of the form $$\begin{pmatrix}a & b & \quad x\quad & 1 & 0\\ c & -a & y & 0 & -1 \\ \\0 & 0 & h & -y^\mathrm{t} & -x^\mathrm{t} \\ \\ 0 & 0 & 0 & a & -b\\ 0 & 0 & 0 & -c & -a\end{pmatrix}$$ for $a,b,c,d$ arbitrary scalars, $x,y$ arbitrary $(n-4)$-vectors, and $h$ arbitrary square matrix of size $n-4$ that is skew-symmetric with respect to the antidiagonal. This has codimension $2n-6$.
In the other direction, we can directly pass to an algebraic closure. Now I borrow the argument from this answer by Peter McNamara: we can suppose that (the projection of) $g$ belongs to closed adjoint orbit in $\mathbf{P}(\so_n)$ (indeed passing from a non-closed orbit to its boundary decreases the orbit dimension and does not decrease the dimension of the centralizer). And (see that same answer), this means that $g$ is, up to conjugation, a nonzero element in a root space. Fixing a Cartan subalgebra, we have 1 or 2 orbits of roots according to whether $n\ge 4$ is even or odd (call them long roots and short roots, assuming that for even $n$ there are only long roots — for $n=3$ there are only short roots). The long roots have a centralizer of codimension $2n-6$ (this is the computation above). Whence this lower bound on the codimension. (The short roots have a centralizer of codimension $2n-4$, but this is a priori only relevant for $n=3$.)
In order to deal with the case $r\le 1$, here's a result in general.
Fix $n\ge 2$. For every nondegenerate quadratic form $q$ in dimension $n$ over a field $K$ of characteristic zero, the codimension of the centralizer of every nonzero semisimple element of $\mathfrak{so}(q)$ is $\ge 2n-4$, which is achieved.
To show that it is achieved, diagonalize $q$, and thus choose an orthogonal decomposition of the ambient space as $V=V_2\oplus V'$ with $V_2$ 2-dimensional. Choose a nonzero element $g$ of the 1-dimensional $\so(q|_{V_2})$. Extend it as zero on $V'$. So we can view $g$ as an element of $\so(q)(K)$. Then its centralizer has codimension $2n-4$. Indeed, to compute it, we can extend extend scalars to assume $K$ algebraically closed (this is inessential, just simplifies computations), and hence we can suppose that the basis is orthonormal. Then $\so(q)$ is the space of skew-symmetric matrices and the centralizer of $g$ consists of those with the (linearly independent) conditions $g_{ij}=0$ for $i=1,2$, $j=3,\dots,n$.
To show that this is a lower bound, we can suppose that the field is algebraically closed. So, we can deal with the bilinear form $b(e_i,e_j)=\delta_{i+j,n+1}$ as above, so that $\so(q)$ consists of skew-symmetric matrices with respect to the skew-diagonal. A Cartan subalgebra consists of those diagonal matrices therein, and we can restrict to elements in this Cartan subalgebra. Replacing each nonzero diagonal entry $x$ with $x/|x|$ will not decrease the centralizer, so we can suppose that $x$ has only the eigenvalues $\pm 1$ and possibly $0$. Then if $m_0$ and $m_1$ are the multiplicity of the eigenvalues $0$ and $1$, we have $n=m_0+2m_1$ and the centralizer has dimension $d=m_1^2+m_0(m_0-1)/2$. Writing $m=m_0$ this yields $d=(n-m)^2/4+m(m-1)/2$ (where $m<n$ is such that $n-m$ is even). One sees this is maximal for $m=n-2$, namely dimension $1+(n-2)(n-3)/2$, and this means codimension $2n-4$.
To conclude the initial result: if the rank $r$ is zero all elements are semisimple and the result follows.
It remains to consider the case of $\so(1,n-1)$ (this might be true over more general fields in rank 1, but I haven't checked). One direction is already settled: there is a semisimple element whose centralizer has codimension $2n-4$. We have to see that every nonzero element $g$ has a centralizer of codimension $\ge 2n-4$. Passing from an element to its nilpotent and semisimple part in the additive Jordan-Dunford decomposition does not decrease the dimension of centralizer. So we can suppose that $g$ is nilpotent or semisimple. The semisimple case is already settled. So we can suppose $g$ nilpotent. All nonzero nilpotent elements in $\so(1,n-1)$ are indeed conjugate and for each of them, the centralizer indeed has codimension $2n-4$.
(At the group level, this centralizer is essentially a semidirect product $\mathbf{R}^{n-2}\rtimes\mathrm{O}(n-3)$, namely the centralizer of a nontrivial translation of $\mathbf{R}^{n-2}$ in its isometry group.)