I'm having trouble understanding why we do this:
Information
Definition. A stochastic process $\{X(t),t\geq 0\}$ is a compound Poisson process if
$$X(t) = \sum_{i=1}^{N(t)} Y_i, \qquad t\geq 0$$
where
$\{N(t),t\geq 0 \}$ is a Poisson process and
$\{Y_i , i = 1,2,3,\ldots\}$ are independent and identically distributed random variables.
Expected Value
This is what they did $$\mathbb{E}(X(t))=\mathbb{E}(\mathbb{E}(X(t)\mid N(t))) \qquad \text{law of total expectation} \\ = \mathbb{E}\left\{\mathbb{E}\left[\sum_{i=1}^{N(t)}Y_i\mid N(t) \right] \right\}\\ = \mathbb{E}(N(t)\mathbb{E}(Y_1)) = \lambda t \mathbb{E}(Y_1).$$
Query
I don't understand why in the first equality, they used the law of total expectation. As in, what's the point? Can't I simply have
$$\mathbb{E}(X(t)) = \mathbb{E} \left(\sum_{i=1}^n Y_i\right)= \sum_{i=1}^{N(t)} \mathbb{E}(Y_i) \qquad \text{by independence} \\ =N(t)\mathbb{E}(Y_1)$$
which is clearly not correct, but why isn't it correct? Also, how did they go from the second equality to the third?
Thanks in advance!
The move that is illegal is: $$ \mathbb E\left(\sum_{i=1}^{N(t)}Y_i\right) = \sum_{i = 1}^{N(t)}\mathbb{E}(Y_i). $$
This would be true if $N(t)$ were nonrandom, but it isn't true if it is random. As Shalop indicated in the comments, it doesn't even make sense since the RHS of the equation is random but the LHS isn't.
But it is in fact true that $$ \mathbb E\left(\sum_{i=1}^{N(t)}Y_i\right) = \mathbb E(N(t))\mathbb E(Y_1),$$ as your first solution showed. This result is a case of Wald's theorem
As for how they got from the second line to the third, they used the fact that since we're conditioning on $N(t)$, it is effectively a constant. Then $$ \mathbb E\left(\mathbb E\left[\sum_{i=1}^{N(t)}Y_i\mid N(t)\right]\right) = \mathbb E\left(\sum_{i=1}^{N(t)}\mathbb E\left[Y_i\mid N(t)\right]\right) =\mathbb E\left(N(t)\mathbb E(Y_i)\right) = \mathbb E(N(t))\mathbb E(Y_i)$$
where in the last two equations we used independence of $N(t)$ and $Y_i$ and the fact that all the $\mathbb E(Y_i)$'s are the same.