This seems to be true and, like many facts about free groups, can be proved using Stallings' famous folding technique. Here's a sketch of the argument.

Think of $F(B)$ as the fundamental group of a bouquet of circles $Y=Y_1\vee Y_2$, where $F(B_i)=\pi_1(Y_i)$. The map $f$ can now be realised as a morphism of graphs $\phi:X\to Y$, where $X$ also decomposes as a wedge $X_1\vee X_2$, with $F(A_i)=\pi_1(X_i)$. Since $f|_{F(A_i)}$ is injective for both $i$, the restriction of $\phi$ to each $X_i$ can be taken to be an immersion. The image $f(F(A))$ is the fundamental group of the graph $\overline{X}$ obtained by folding the map $\phi$. Since $\phi|_{X_1}$ is an immersion, $\phi$ embeds $X_1$ into $\overline{X}$, and we may therefore identify $X_1$ with its image in $\overline{X}$.

We now need to interpret hypothesis 2. Let $Z$ be the graph obtained by collapsing each edge in $\overline{X}$ that maps to $Y_1$, and let $\psi:Z\to Y_2$ be the map induced by $\phi$. The image of $p_2\circ f|_{F(A_2)}$ is identified with the fundamental group of $\overline{Z}$, the graph obtained by folding the map $\psi$.

The second hypothesis now tells us that $b_1(\overline{Z})=b_1(X_2)$, where $b_1$ denotes first Betti number, i.e. the rank of the fundamental group.

We can now conclude by estimating first Betti numbers. Since $\overline{Z}$ is obtained by folding $\psi$, we have

$b_1(X_2)=b_1(\overline{Z})\leq b_1(Z)$ .

Since $Z$ was obtained from $\overline{X}$ by collapsing a subgraph that contained $X_1$, we have

$b_1(Z) + b_1(X_1)\leq b_1(\overline{X})$,

and since $\overline{X}$ was obtained by folding $\phi$, we have

$b_1(\overline{X})\leq b_1(X)$ .

Putting these together gives

$b_1(X)=b_1(X_1)+b_1(X_2)\leq b_1(\overline{X})\leq b_1(X)$

so $b_1(\overline{X})= b_1(X)$. This tells us that the rank of the image of $f$ is equal to the rank of $F(A)$. Since free groups are Hopfian, it follows that $f$ is injective, as required.