If we consider the polynomial $f(x)=x^3-3x-1 \in \mathbb{Q}[x]$ which has 3 real roots $\{x_1,x_2,x_3\}$. I read that its galois group is isomorphic to $A_3$ and not to $S_3$. I don't really understand this.
If I consider the map (Here $E$ is the splitting field of $f$ over $\mathbb{Q})$:
\begin{align*}
\sigma \colon E \to E\\
x_1 \mapsto x_2\\
x_3 \mapsto x_3\\
\mathbb{Q} \mapsto \mathbb{Q}
\end{align*}
This would correspond to a transposition $(12)$ which is not in the alternating group.
But isn't this a $\mathbb{Q}$-automorphism? I actually don't really grasp why the Galois group isn't in general isomorphic to Sn (for n distinct roots).
TL;DR The element $(x_1-x_2)(x_1-x_3)(x_2-x_3)$ is contained in $\Bbb{Q}$ but not fixed by $\sigma$.
The following theorem tells us when the Galois group of a polynomial over $\Bbb{Q}$ is contained in $A_n$:
The proof shows in particular why your map is not a field automorphism of $E$:
Let $x_1,\ldots,x_n\in E$ be the roots of $f$ and let $S_n$ act on $E$ by its action on the indices of the roots, i.e. $\sigma(x_i):=x_{\sigma(i)}$ for all $i$. Consider the element $$\delta:=\prod_{1\leq i<j\leq n}(x_i-x_j)\in E.$$ Note that for all $\sigma\in S_n$ we have $\sigma(\delta)=\operatorname{sgn}(\sigma)\delta$ and that $\delta^2=\Delta(f)$.
If $\Delta(f)$ is a square in $\Bbb{Q}$ then it $\delta\in\Bbb{Q}$. It follows that $\sigma(\delta)=\delta$ for all $\sigma\in\operatorname{Gal}(E\Bbb{Q})$ and hence that $\operatorname{sgn}(\sigma)=1$ for all $\sigma\in\operatorname{Gal}(E\Bbb{Q})$. This means precisely that $\operatorname{Gal}(E\Bbb{Q})$ is contained in $A_n$.
In this particular case we see that $\Delta(x^3-3x-1)=81$, so the element $$\delta=(x_1-x_2)(x_1-x_3)(x_2-x_3)=\pm9,$$ is not fixed by your map $\sigma$, so $\sigma$ cannot be a field automorphism of $E$.