The question is like this:
IF $G=S_5$ and $g=(1\quad 2\quad 3)$, determine the number of elements in $H=\{x\in G:xg=gx\}$.
To do the question, first it says $$x(4)=(x(1\quad 2\quad 3))(4)=(1\quad 2\quad 3)x(4)$$ so $g(4)=4\ or\ 5$. Similarly, $g(5)=4\ or\ 5$.
Hence $g(\{4,5\})=\{4,5\}$ and also $g(\{1,2,3\})=\{1,2,3\}$.
My understanding for this part is that this is because the permutation $(1\quad 2\quad 3)$ has nothing to do on 4 or 5. Is this correct ?
But then it says this means $x$ must be one of the following: $$id,\ (1\quad 2\quad 3),\ (1\quad 3\quad 2),\ (4\quad 5),\ (1\quad 2\quad 3)(4\quad 5),\ (1\quad 3\quad 2)(4\quad 5)$$ I'm wondering how these are found? How do we find those $x$ satisfying $xg=gx$?
For example, what if I change the question as $G=S_6$ and $g=(1\quad 2\quad 3\quad 4)$ or $g=(1\quad 2\quad 3)$?
And how can we determine if two permutations commute without actual calculation?
What your first observation amounts to is that $H$ is (isomorphic to) a subgroup of $S_3 \times S_2$, where the first factor acts on $\{1,2,3\}$ and the second factor acts on $\{4,5\}$. This only has $12$ elements, which is a drastic reduction from the $120$ elements of $S_5$ we would have to test by "brute force".
Moreover, it can be seen that any element (corresponding to an element) of the form $(e_{S_3},\sigma)$, for either of the two elements $\sigma \in S_2$ will be in $H$, since disjoint cycles commute. Hence:
$gx = xg \iff (g_1,\sigma)((1\ 2\ 3),e_{S_2}) = ((1\ 2\ 3),e_{S_2})(g_1,\sigma)$
and since the second coordinate is always $\sigma$:
$\iff g_1(1\ 2\ 3) = (1\ 2\ 3)g_1$
So it really boils down to which elements of $S_3$ commute with $(1\ 2\ 3)$. Clearly, any power of $(1\ 2\ 3)$ commutes with $(1\ 2\ 3)$, and since these form fully half of $S_3$, and $S_3$ is non-abelian, this must be all of them (since any subgroup of $S_3$ which contains more than half the elements of $S_3$ must be $S_3$ itself).
Thus $H = \langle (1\ 2\ 3),(4\ 5)\rangle \cong \langle(1\ 2\ 3)\rangle \times \langle(4\ 5)\rangle \cong \Bbb Z_3 \times \Bbb Z_2 \cong \Bbb Z_6$; in fact, $H$ is cyclic with generator $(1\ 2\ 3)(4\ 5)$, and the six explicit permutations you listed are the powers of this generator.
I hope this makes it clearer how to extend this reasoning to $S_n$ for the same 3-cycle. For a 4-cycle like $(1\ 2\ 3\ 4)$, you'd have to look at which elements of $S_4$ commute with that 4-cycle, which takes a little more work than with a 3-cycle.