The other answers consider the case where the bundle in question is orientable. It's then natural to ask if $v \in H^2(M; \mathbb{Z}/2)$ can be realised as $w_2(E)$ for some vector bundle $E$, is it necessarily realised as $w_2(E')$ for some orientable vector bundle $E'$? It turns out that the answer is yes!
To see this, let $L$ denote the determinant line bundle of $E$ and note that $w_1(E) = w_1(L)$. Consider the vector bundle $E' := (E\oplus L\oplus\varepsilon^k)\otimes L$ where $k$ is chosen such that $\operatorname{rank}(E\oplus L\oplus\varepsilon^k) = 4p + 2$ for some $p$. Using the formulae for the first and second Stiefel-Whitney classes of a tensor product (see this note for example), we have
\begin{align*}
w_1(E') &= w_1((E\oplus L\oplus\varepsilon^k)\otimes L)\\
&= \operatorname{rank}(L)w_1(E\oplus L\oplus\varepsilon^k) + \operatorname{rank}(E\oplus L\oplus\varepsilon^k)w_1(L)\\
&= w_1(E) + w_1(L) + (4p+2)w_1(L)\\
&= 0
\end{align*}
and
\begin{align*}
w_2(E') &= w_2((E\oplus L\oplus\varepsilon^k)\otimes L)\\
&= \binom{1}{2}w_1(E\oplus L\oplus\varepsilon^k)^2 + \binom{4p+2}{2}w_1(L)^2 + 1^2w_2(E\oplus L\oplus\varepsilon^k)\\
&\quad\, + (4p+2)^2w_2(L) + (4p+1)w_1(E\oplus L\oplus\varepsilon^k)w_1(L)\\
&= 0 + w_1(L)^2 + w_2(E\oplus L) + 0 + w_1(E\oplus L)w_1(L)\\
&= w_1(L)^2 + w_2(E) + w_1(E)w_1(L) + w_2(L) + (w_1(E) + w_1(L))w_1(L)\\
&= w_1(L)^2 + w_2(E) + w_1(L)^2 + 0 + 0\\
&= w_2(E).
\end{align*}
Therefore, if $E$ is a vector bundle with $w_2(E) = v$, then $E'$ is an orientable vector bundle with $w_2(E') = v$.
This observation can be used to show that the set of cohomology classes which can be realised as $w_2(E)$ for some vector bundle $E$ is a subspace of $H^2(M; \mathbb{Z}/2)$. The only condition that needs to be verified is that the sum of realisable cohomology classes is again realisable. If $v_1$ and $v_2$ are realised, then by the above, we can find orientable bundles $E_1$ and $E_2$ such that $w_2(E_i) = v_i$. By taking the direct sum with a trivial bundle if necessary, we can arrange for $E_1$ and $E_2$ to have odd ranks $m_1$, $m_2$ respectively. It then follows from the same tensor product formula that
$$w_2(E_1\otimes E_2) = m_2^2w_2(E_1) + m_1^2w_2(E_2) = w_2(E_1) + w_2(E_2) = v_1 + v_2,$$
so $v_1 + v_2$ is realisable.