I think your answer is that because the second case is written in prenex normal form while the first one isn't. You can read about prenex normal form in logic more for example here and here.
If I want to explain your cases briefly we have followings in the formal predicate calculus (from page 84 of Logics for mathematicians, Hamilton)
Let $\mathcal{A}$ and $\mathcal{B}$ be two statements and $x_i$ be the statements variables
First, if $x_i$ does not occur free in $\mathcal{B}$, then we have
$$\vdash ((\forall x_i) (\mathcal{A} \rightarrow \mathcal{B})\iff ((\exists x_i)\mathcal{A} \rightarrow \mathcal{B})) \quad*\\
\vdash ((\exists x_i) (\mathcal{A} \rightarrow \mathcal{B})\iff ((\forall x_i)\mathcal{A} \rightarrow \mathcal{B}))
$$
second, if $x_i$ doesn't occur free in $\mathcal{A}$ we have
$$\vdash ((\forall x_i) (\mathcal{A} \rightarrow \mathcal{B})\iff (\mathcal{A} \rightarrow (\forall x_i)\mathcal{B}))\\
\vdash ((\exists x_i) (\mathcal{A} \rightarrow \mathcal{B})\iff (\mathcal{A} \rightarrow (\exists x_i)\mathcal{B}))$$
Let $x_i$ be the $y$ you've denoted as a pumpkin. Also, let $\mathcal{A}$ be $\mathbf{pumpkin}(y)\, \wedge \mathbf{buy}(x,y)$ and $\mathcal{B}$ be $\mathbf{carve(x,y)} \wedge \mathbf{eat}(x,y)$. We have following statement by ignoreing the part anyone who
$$(\exists y) \mathcal{A} \rightarrow \mathcal{B} ,$$
that we can rewrite it by above proposition $*$ as follows (Note $y$ is not free in $\mathcal{B}$)
$$(\forall y) (\mathcal{A} \rightarrow \mathcal{B}) $$
Therefore two following statements are equivalent in logic by considering the first part we have ignored, that is
$$(\forall x)(\forall y) (\mathcal{A} \rightarrow \mathcal{B}) \equiv (\forall x) ((\exists y) \mathcal{A} \rightarrow \mathcal{B}) .$$
Note that you are not allowed to write your first statement in prenex normal form because $y$ is free in $\mathcal{B}=\mathbf{fanatic}(x)$.
As a practice, you can prove the four above propositions.