It is not always possible to expand $\mathbb{E}[e^{\lambda X}]$ into a power series in $\lambda$, implying that we need some condition for the proposed equality to hold.
In this regard, we have:
Theorem 1. Let $X$ be a real-valued random variable. Then the followings are equivalent:
- There exists an open interval $I$ containing $0$ such that $\mathbb{E}[e^{\lambda X}] < \infty$ for all $\lambda \in I$.
- There exists $\varepsilon > 0$ such that $\mathbb{E}[e^{\varepsilon|X|}] < \infty$.
- $\mathbb{E}[X^k]$ is finite for all $k \geq 0$ and $\sum_{k=0}^{\infty} \frac{\lambda^k}{k!}\mathbb{E}[X^k]$ converges for some $\lambda \neq 0$.
We also have:
Theorem 2. Let $X$ be a real-valued random variable. Then
$$ \mathbb{E}[e^{\lambda X}] = \sum_{k=0}^{\infty} \frac{\lambda^k}{k!}\mathbb{E}[X^k] $$
whenever the right-hand side converges.
Proof of Theorem 1. We show that $(1) \implies (2) \implies (3) \implies (1)$.
$(1) \implies (2)$ : Choose $\varepsilon > 0$ so that $\pm \varepsilon \in I$. Then
$$ \mathbb{E}[e^{\epsilon|X|}] \leq \mathbb{E}[e^{\epsilon X} + e^{-\epsilon X}] < \infty. $$
$(2) \implies (3)$ : Tonelli's Theorem allows us to interchange the order of expectation and infinite summation when all the summands are non-negative, regardless of the convergence. Hence,
$$ \mathbb{E}[e^{\epsilon|X|}]
= \mathbb{E}\left[ \sum_{k=0}^{\infty} \frac{\varepsilon^k}{k!}|X|^k \right]
= \sum_{k=0}^{\infty} \frac{\varepsilon^k}{k!}\mathbb{E}[|X|^k]. $$
Now the desired claim follows by noting that $\mathbb{E}[e^{\epsilon|X|}] < \infty$ and that $|\mathbb{E}[X^k]| \leq \mathbb{E}[|X|^k]$ for any $k \geq 0$.
$(3) \implies (1)$ : Write $R = |\lambda|$. Then by the standard theory of power series, we know that
$$ f(z) = \sum_{k=0}^{\infty} \frac{z^k}{k!}\mathbb{E}[X^k] $$
converges for any $z \in (-R, R)$. Then for any such $z$, invoking Tonelli's Theorem gives
$$ \mathbb{E}[e^{zX}] \leq 2 \mathbb{E}[\cosh(zX)] = 2 \sum_{k=0}^{\infty} \frac{z^{2k}}{(2k)!}\mathbb{E}[X^{2k}] = f(z) + f(-z), $$
which is finite. So, we can set $I = (-R, R)$.
Proof of Theorem 2. Suppose $\lambda$ is such that $\sum_{k=0}^{\infty} \frac{\lambda^k}{k!}\mathbb{E}[X^k]$ converges. Since the statement is trivial when $\lambda = 0$, we can assume $\lambda \neq 0$. Moreover, replacing $X$ and $\lambda$ by $-X$ and $-\lambda$, if necessary, we can assume $\lambda > 0$ and we do so.
Now by mimicking the previous proof, we know that $\mathbb{E}[e^{|zX|}] < \infty$ for any $z$ satisfying $|z| < \lambda$, which in turn implies that we can invoke Fubini's Theorem to have
$$ \mathbb{E}[e^{zX}] = \sum_{k=0}^{\infty} \frac{z^k}{k!}\mathbb{E}[X^k] $$
whenever $|z| < \lambda$. Now, let $X_+ = \max\{0, X\}$ and $X_- = \max\{0, -X\}$ denote the positive and negative part of $X$, respectively. Then by Monotone/Dominated Convergence Theorem and Abel's Theorem,
\begin{align*}
\mathbb{E}[e^{\lambda X}]
&= \mathbb{E}[e^{\lambda X_+}\mathbf{1}_{\{X \geq 0\}}] + \mathbb{E}[e^{-\lambda X_-}\mathbf{1}_{\{X < 0\}}] \\
&= \underbrace{\lim_{z \to \lambda^-} \mathbb{E}[e^{z X_+}\mathbf{1}_{\{X \geq 0\}}]}_{\text{by MCT}} + \underbrace{\lim_{z \to \lambda^-} \mathbb{E}[e^{-z X_-}\mathbf{1}_{\{X < 0\}}]}_{\text{by DCT}} \\
&= \lim_{z \to \lambda^-} \mathbb{E}[e^{z X}] \\
&= \lim_{z \to \lambda^-} \sum_{k=0}^{\infty} \frac{z^k}{k!}\mathbb{E}[X^k] \\
&= \sum_{k=0}^{\infty} \frac{\lambda^k}{k!}\mathbb{E}[X^k] \tag{by Abel's Theorem}
\end{align*}