We can prove the non-second-order version as follows:
Given the assumption $A \rightarrow B$, we can obtain $\neg B \rightarrow \neg A$ by the intuitionistically valid direction of taking contrapositives (see here).
If we also have $\neg A \rightarrow B$, transitivity of implication gets us to $\neg B \rightarrow B$, which is equivalent to $\neg\neg B$.
Alternative proof of this first claim: given $A\rightarrow B$ and $\neg A \rightarrow B$, we have $(A \vee \neg A) \rightarrow B$, and therefore $\neg\neg(A \vee \neg A) \rightarrow \neg\neg B$ using the fact that double negation distributes over implication (two uses of contraposition). But $\neg\neg(A \vee \neg A)$ is provable by Glivenko's theorem, so $\neg\neg B$ follows.
For the second-order version, we can argue as follows:
If there's some proposition $A$ such that $(A \vee \neg A) \rightarrow B$, then the previous argument lets us conclude $\neg\neg B$ again. This takes care of one direction.
For the other direction, assume $\neg\neg B$ holds. We need to prove that there's some $A$ such that assuming $A \vee \neg A$ lets us conclude $B$.
But setting $A:=B$ suffices. If we assume $B \vee \neg B$, then we can argue by cases. In the first case, $B$ holds so we're done. In the second case, $\neg B$ holds, which contradicts $\neg\neg B$: but everything follows from a contradiction, including $B$. In either case, $B$ follows, so we have managed to prove $(B\vee \neg B)\rightarrow B$, and hence $\exists A. (A \vee \neg A)\rightarrow B$, from the assumption $\neg\neg B$.