If all maps are involved are pointed, your question is equivalent to the following: if $f : X \to BG$ is a map (where $X$ is connected) such that the induced map on $\pi_{\bullet}$ is zero, is $f$ zero (nullhomotopic)? The answer is no, although it's easiest to give a counterexample if we replace $BG$ with an arbitrary space $Y$ (although if $G$ is allowed to be any topological group, $BG$ can be any connected space).
For example, if $X = BG$ for a discrete group $G$ and $Y = B^2 A$ for an abelian group $A$, then $X$ and $Y$ do not share nonzero homotopy groups in any degree, but maps $BG \to B^2 A$ correspond to classes in group cohomology $H^2(G, A)$, or equivalently to central extensions $A \to E \to G$. (This is a basic but important class of counterexamples to many naive guesses about how homotopy theory and higher category theory work; for example, it shows that a functor between 2-categories is not determined by what it does to objects, morphisms, and 2-morphisms. In this case all of the interesting data of a map $BG \to B^2 A$ is in coherence isomorphisms.)
As for what goes wrong in your proof, the condition says that if $g : S^n \to X$ is any map, there exists some trivialization of the pullback bundle $g^{\ast} P$. But in order to deduce from hereThis means that the natural map $\pi_0 [S^n, E_f] \to \pi_0 [S^n, X]$ is a surjection, not a bijection. To get a bijection on $[S^n, X] \cong [S^n, E_f]$$\pi_0$ you need thesealso want trivializations to depend continuously on $g$ (this is necessary but not sufficient). This is analogous to the difference between a space being path-connected and being contractible. It's importantbe unique up to remember that trivializations are structurehomotopy.
Explicitly, letLet's see explicitly how your proof breaks down in the above example. Let $n = 1$ in the example $X = BG, Y = B^2 A$ above. Here the homotopy fiber of a map $f : BG \to B^2 A$ is $BE$ where $E$ is the central extension classified by $f$. A map $g : S^1 \to BG$ picks out an element $g \in G$ (conveniently). The composite $f \circ g : S^1 \to B^2 A$ is always nullhomotopic, so each $g$ always lifts to a map $\widetilde{g} : S^1 \to BE$, or equivalently an element $\widetilde{g} \in E$, which is clear since $E \to G$ is surjective, so admits a section. But what we actually want is that $BE \to BG$ admits a sectionlifts are not unique, and we don't have that here; this is equivalent to requiring thatthere's no reason we can choose lifts so that $g \mapsto \widetilde{g}$ is a homomorphism (which would correspond to a section of $BE \to BG$).