In actuarial science, this is the basic form of a collective risk model. There is a discrete distribution from which an annual loss frequency is drawn, and each of those losses has a severity drawn from some continuous distribution. The sum total of those losses is the expected aggregate loss the insurer/reinsurer/homeowner/etc. expects.
Somewhat more formally, if $N$ is a discrete random variable, and $X$ is a continuous random variable, we can define $S$ as the aggregate loss random variable where $S = X_1 + X_2 + \ldots + X_N, X \in {0, 1, 2, \ldots}$.
Given some basic independence assumptions, simply the $X's$ (jointly or singly) do not depend on $N$ and vice versa, it can be shown that:
$$
E(S) = E(N)E(X)\\
Var(S) = E(N)Var(X) + Var(N)E(X)^2
$$
The proof is based on convolution of the probability generating functions. See (Klugman et al. 1998, pp.295–298).
As soakley showed below, the first expectation is relatively simple to derive. The second can be understood knowing the law of total variance which is:
$$
Var(X) = E_Y[Var(X|Y)] + Var_Y[E(X|Y)]
$$
or, in English, the total variance is the expected value of the conditional variance plus the variance of the conditional expected value. See (Heckman & Meyer 1989, p.30) for this derivation.
Adding derivation of Variance (edit)
Given the law of total probability, we can say that $Var(S) = E[Var(S|N)] + Var[E(S|N)]$. Now, $S|N$ is merely $X_1 + X_2 + \ldots + X_N$, and we are given the value of $n$. So let's rewrite.
$$
Var(S) = E[Var(X_1 + X_2 + \ldots + X_N)] + Var[E(X_1 + X_2 + \ldots + X_N)]
$$
One of our assumptions in compound variance, which you also mentioned in your question, is that the X's are iid. Therefore, in the first term, $Var(X_1 + X_2 + \ldots + X_N)$ collapses to $N\cdot Var(X)$. Similarly, the second term $E(X_1 + X_2 + \ldots + X_N)$ simply becomes $N*E(X)$, so we now have:
$$
Var(S) = E[N\cdot Var(X)] + Var(N\cdot E(X)]
$$
To complete the conditioning, we need to take the expectations and variances over $N$. But the $X$'s are constants with respect to $N$, so we get:
$$
Var(S) = E[N]Var(X) + Var(N)E[X]^2
$$
since the $E(X)$ component in the variance comes outside squared and the $Var(X)$ component in the expectation comes out directly, which demonstrates the second relationship.
Heckman, Philip E., and Glenn G. Meyers. "The calculation of aggregate
loss distributions from claim severity and claim count distributions."
Proceedings of the Casualty Actuarial Society. Vol. 70. 1983.
Klugman, S. A.; Panjer, H. H. & Willmot, G. E. Loss models: from data
to decisions John Wiley & Sons, Inc., 1998
Best Answer
$$ \Pr(\max\{X_1,X_2\} = X_2\mid X_2=x)=\Pr(X_2>X_1\mid X_2=x) = \Pr(x>X_1)=x. $$ The probability distribution of $\max$ given that $\max\ne X_2$ and $X_2=x$ is the probability distribution of $X_1$ given $X_1>x$, so that is uniform on $[x,1]$.
So \begin{align} & \mathbb E(\max\mid X_2=x) \\[8pt] = {} & \Pr(\max=x\mid X_2=x)\mathbb E(\max\mid \max=x\ \&\ X_2=x) \\ & {} + \Pr(\max\ne x\mid X_2=x) \mathbb E(\max\mid \max\ne x\ \&\ X_2=x) \\[8pt] = {} & x^2 + (1-x)\cdot \frac{x+1}2 = \frac{1+x^2}2. \end{align}
Therefore $$\mathbb E(\max\mid X_2) = \dfrac{1+X_2^2}2.$$