In the comments to your question, a reference is given to Rudin's Real and Complex Analysis. Since you are asking about the Bochner integral, while Rudin and most textbook treatments of integration focus on real and complex-valued integrals, you'd probably prefer a reference that addresses the question in the context of the Bochner integral. See Theorem 5.15 in Lang's Real and Functional Analysis (3rd ed.). Here is the statement there, with a few edits I explain after the theorem.
Theorem. Let $f \in L^1(\mu,E)$ and $S$ be a closed subset of $E$ such that
$$
\frac{1}{\mu(A)}\int_A f\,{\rm d}\mu \in S
$$
for all measurable $A \subset X$ with finite positive measure and either $0 \in S$ or $X$ is $\sigma$-finite. Then $f(x) \in S$ for $\mu$-almost all $x \in X$.
Lang actually starts the theorem with "$f \in \mathscr L^1(\mu,E)$", where $\mathscr L^1(\mu,E)$ is defined on the bottom of p. $128$, and such functions might not be measurable initially. At the start of section IV on p. $134$ he notes such $f$ can be taken to be measurable by adjusting them on a set of measure $0$, and on p. 139 he notes $L^1(\mu,E)$ is the quotient space of $\mathscr L^1(\mu,E)$ modulo the subspace of functions that vanish almost everywhere.
Lang left out the conditions that $0 \in S$ or $X$ is $\sigma$-finite, but a counterexample without at least one of these conditions is the following.
Let $X = \{a,b\}$ be a two-point space and $\mu$ be the measure on $X$ with $\mu(a) = 1$ and $\mu(b) = \infty$, so $(X,\mu)$ is not $\sigma$-finite. Let $E = \mathbf R$ and
$f \colon X \to E$ where $f(a) \not= 0$ and $f(b) = 0$. Set $S = \{f(a)\}$, so $f \in L^1(\mu,E)$ and $S$ is closed in $E$, but $0 \not\in S$. The integration hypothesis in the theorem is satisfied, but it's not true that $f(x) \in S$ for $\mu$-almost all $x \in X$, as $f(b) \not\in S$ and $\mu(\{b\}) = \infty$.