Let $B$ be a closed manifold with such that every vector bundle is trivial. Then $H^1(B; \mathbb{Z}_2) = 0$, otherwise there would be a non-trivial line bundle. Therefore every bundle over $B$ is orientable and $B$ itself is orientable. Orientable rank two bundles over $B$ are classified by $H^2(B; \mathbb{Z})$, so we must have $H^2(B; \mathbb{Z}) = 0$. It follows these conditions that there are no examples with $\dim B = 1, 2$. If $\dim B > 2$ we then have to consider the possibility of non-trivial bundles of rank at least three.

Suppose now that $\dim B = 3$. As $B$ is closed and orientable we have $H_1(B; \mathbb{Z}) \cong H^2(B; \mathbb{Z}) = 0$ by Poincaré duality and $H^3(B; \mathbb{Z}) \cong \mathbb{Z}$. It follows that $B$ is an integral homology sphere - note, the condition $H^1(B; \mathbb{Z}_2) = 0$ is superfluous in this case as $H^1(B; \mathbb{Z}) \cong \operatorname{Hom}(H_1(B; \mathbb{Z}), \mathbb{Z}_2)$ by the Universal Coefficient Theorem. We still have to consider the possibility of non-trivial bundles of rank at least three. 

Suppose $E \to B$ has rank greater than three, then $E\cong E_0\oplus\varepsilon^k$ for some rank three bundle $E_0$, see [this answer](https://mathoverflow.net/a/417820/21564); in particular, we only need to consider the possibility of a non-trivial vector bundle of rank three. Suppose then that $\operatorname{rank} E = 3$. As $E$ is orientable, it has an Euler class $e(E)$ which is the first obstruction to a nowhere-zero section (it is also the only obstruction because $\operatorname{rank}E = \dim B$). As $E$ has odd rank, the Euler class of $E$ is two-torsion, but $e(E) \in H^3(B; \mathbb{Z}) \cong \mathbb{Z}$ which is torsion-free, so $e(E) = 0$. Therefore $E \cong E_0\oplus\varepsilon^1$ where $\operatorname{rank}E_0 = 2$. As we already know rank two bundles over $B$ are trivial, we see that $E$ is also trivial.

In conclusion, we have the following:

> Let $B$ be a closed three-manifold. Every vector over $B$ is trivial if and only if $B$ is an integral homology sphere.

Note, we only considered real vector bundles above, but the same is true for complex vector bundles since every such bundle is the direct sum of a trivial bundle and a complex line bundle, but the latter are classified by $H^2(B; \mathbb{Z}) = 0$.

The fact that every vector bundle over a three-dimensional integral homology sphere is trivial can also be seen using [Quillen's plus construction](https://encyclopediaofmath.org/index.php?title=Plus-construction) (also see section $\mathrm{IV}.1$ of Weibel's *An Introduction to Algebraic K-Theory*). As $B$ is an integral homology sphere, its fundamental group $\pi_1(B)$ is perfect. By the plus construction, there is a simply connected CW complex $B^+ = B^+_{\pi_1(B)}$ and a map $q : B \to B^+$ inducing isomorphisms on homology satisfying the following: if $f : B \to X$ is a map with $\ker f_* : \pi_1(B) \to \pi_1(X)$ equal to $\pi_1(B)$, then there is a map $g : B^+ \to X$, unique up to homotopy, such that $f = g\circ q$. As $H^1(B; \mathbb{Z}_2) = 0$, every bundle over $B$ is orientable and hence classified by a map $f : B \to BSO(n)$. Since $\pi_1(BSO(n)) \cong \pi_0(SO(n)) = 0$, the kernel of $f_* : \pi_1(B) \to \pi_1(BSO(n))$ is $\pi_1(B)$ so $f = g\circ q$ for some map $g : B^+ \to BSO(n)$. Note that $B^+$ is a simply connected CW complex with $H_*(B^+) \cong H^+(S^3)$, so $B^+$ is homotopy equivalent to $S^3$ by the homological Whitehead Theorem. As $\pi_3(BSO(n)) \cong \pi_2(SO(n)) = 0$, the maps $g$ and $f$ are nullhomotopic, so $f$ classifies the trivial bundle. Replacing $BSO(n)$ with $BU(n)$ yields the same result for complex vector bundles.

As for higher-dimensional examples, note that they must have odd dimension. To see this, suppose $\dim B = 2m$. Choose a degree one map $\varphi : B \to S^{2m}$ and consider the bundle $\varphi^*TS^{2m} \to B$. As $e(TS^{2m}) \neq 0$ and $\varphi^* : H^{2m}(S^{2m}; \mathbb{Z}) \to H^{2m}(B; \mathbb{Z})$ is an isomorphism, we see that $e(\varphi^*TS^{2m}) = \varphi^*e(TS^{2m}) \neq 0$ and hence $\varphi^*TS^{2m}$ is non-trivial. If one considers complex bundles instead, the same argument works by replacing $TS^{2m}$ with a complex vector bundle $E$ with $e(E) = c_n(E) \neq 0$ - such a bundle always exists as $\operatorname{ch} : K(S^{2m})\otimes\mathbb{Q}\to H^{\text{even}}(S^{2m}; \mathbb{Q})$ is an isomorphism.

One last comment about dimension five. As was established by Jason DeVito [here](https://math.stackexchange.com/a/4409768/39599), $B$ must be a rational homology sphere. If a five-dimensional example exists, I claim it is also a $\mathbb{Z}_2$ homology sphere. To see this, first note that we have $H^1(B; \mathbb{Z}_2) = 0$ from above. Now, if $v \in H^2(B; \mathbb{Z}_2)$, then there is a bundle $E \to B$ with $w_2(E) = v$ if and only if $\beta(v^2) \in H^5(B; \mathbb{Z})$ is zero where $\beta$ denotes the mod $2$ Bockstein, see [this answer](https://mathoverflow.net/a/344172/21564). As $\beta(v^2)$ is two-torsion and $H^5(B; \mathbb{Z}) \cong \mathbb{Z}$ is torsion-free, we see that $\beta(v^2) = 0$ for every $v \in H^2(B; \mathbb{Z}_2)$, so every such class arises as $w_2(E)$ for some $E$. Therefore, we must have $H^2(B; \mathbb{Z}_2) = 0$. The claim now follows by Poincaré duality.