[Expanding my earlier comment into an answer]:

Self-dual cuspidal automorphic representations of $GL(n)$ have been classified by Jim Arthur, as one of the main results of his monograph on automorphic forms for classical groups.

The general shape of the classification is this. If $\pi$ is self-dual, then the Rankin--Selberg $L$-function $L(\pi \times \pi, s)$ has a simple pole at $s = 1$. On the other hand, this $L$-function factors as $L(Sym^2 \pi, s) \times L(\wedge^2 \pi, s)$, and neither can vanish at $s = 1$. So if $\pi$ is self-dual, exactly one of these functions has a pole. We say a selfdual $\pi$ is of **orthogonal type** if $Sym^2 \pi$ has a pole, and of **symplectic type** if $\wedge^2 \pi$ has a pole.

If $\pi$ has a Galois representation attached, then you can easily convince yourself that orthogonal / symplectic type is precisely saying that the Galois representation lands in an orthogonal, resp. symplectic, group; and this leads one to expect that $\pi$ should be a functorial transfer from the Langlands duals of these groups. This, if I understand correctly, is exactly what Arthur proves. More precisely:

- if $\pi$ is symplectic, then $n = 2m$ has to be even, and $\pi$ should be a functorial transfer from the dual group of $Sp(2m)$, which is $SO(2m+1)$.
- if $\pi$ is orthogonal and $n = 2m+1$ is odd, then, up to a quadratic twist coming from the quotient $O(2m+1)/SO(2m+1)$, $\pi$ must be a functorial transfer from the dual group of $SO(2m+1)$, which is $Sp(2m)$.
- if $\pi$ is orthogonal and $n = 2m$ is even, then either the Langlands parameter of $\pi$ factors through $SO(2m)$, in which case $\pi$ comes from the Langlands dual of $SO(2m)$ which is $SO(2m)$ again; or there is a non-trivial quadratic character intervening, in which case $\pi$ comes from a twisted form of $SO(2m)$.

Let me make this explicit in some small cases.

If $n = 2$ then we have $\tilde\pi = \pi \otimes \omega_{\pi}^{-1}$, as @PeterHumphries has pointed out. Hence there are two ways $\pi$ can be selfdual: we may have $\omega_{\pi} = 1$, in which case $\pi$ is of symplectic type and is a functorial lift from $PGL_2 \cong SO(3)$; or we may have $\omega_\pi \ne 1$ but still $\pi \cong \pi \otimes \omega_\pi^{-1}$, so $\omega_{\pi}$ has to be quadratic and $\pi$ is a dihedral representation induced from the corresponding quadratic field -- which is precisely saying that $\pi$ is of orthogonal type and comes from a twisted form of $SO(2)$.

If $n = 3$, then this recovers Ramakrishnan's theorem that $\pi$ has to come from $SL(2)$ via the adjoint square lift, up to twisting by a quadratic character.

If $n = 4$, then there are two possibilities again: either $\pi$ is symplectic, so it comes from $SO(5) \cong PGSp(4)$; or $\pi$ is orthogonal, in which case it comes from a (possibly) twisted form of $SO(4)$. The split form of SO(4) is a quotient of $SL(2) \times SL(2)$, so we get $\pi$'s that are transfers from $GL_2 \times GL_2$ via the Rankin--Selberg lifting, and the non-split forms correspond to Asai transfers from $GL_2$ over a quadratic field extension.