Is every finite $p$-group an epimorphic image of a fibered product of two finite $p$-groups which can be generated by $2$ elements?



Finite p-groups and their fibered products
No, you cannot obtain all finite $p$-groups in this way; you even miss some $p$-groups of nilpotency length 2 (although you have all abelian $p$-groups as I mentioned in a comment).


Lemma: Let $G$ be a fibered product of $G\_1$ and $G\_2$. Let $L$ be a subgroup of $G$ both of whose projection on $G\_1$ and $G\_2$ are onto, and let $N$ be the normal subgroup of $G$ generated by $L$. Then $G/N$ is abelian.


Proof: Let $G$ be fibered product of $G\_1\stackrel{f\_1}\to H\stackrel{f\_2}\leftarrow G\_2$. Let $K\_i$ be the kernel of $f\_i$. Let $p$ be the projection $G\to G/N$. It follows from the definition of $N$ that $p(K\_1\times K\_2)=G/N$. So to show that $G/N$ is abelian, it is enough to show that $p(K\_1)$ is abelian, i.e., $p([K\_1,K\_1])$ is abelian. If $u,v\in K\_1$, let $w$ be an element in $G\_2$ such that $(v,w)\in L\subset N$. Then
$$p([u,v],1)=p([(u,1),(v,w)])=[p(u,1),p(v,w)]=[p(u,1),1]=1.\qquad\Box$$


To apply the lemma in your context, assume that $G\_1$ and $G\_2$ are generated by $k\_1$ and $k\_2$ elements (you have $k\_1=k\_2=2$ but the argument is more general). Then we can find $L$ as in the lemma, generated by $k=k\_1+k\_2$ elements (actually we could even do $k\_1+k\_2-s$ where $s$ is the minimal number of generators of $H$). Hence there exist $s$ elements in $G$ ($s=4$ in your case) such that the quotient of $G$ by the normal subgroup generated by these $s$ elements is abelian.


It is thus enough to find a $p$-group in which this does not hold. For instance, if we take a free group on $c$ generators in the variety of 2-nilpotent groups of exponent $p$ (exponent 4 if $p=2$) then it works: such a group is thus not (a quotient of) a fibered product of 2 2-generated groups if $c$ is large enough (namely $c\ge 6$), because its quotient by the normal subgroup generated by 4 elements is never abelian.


Edit: here's a proof of the latter fact (for odd prime $p$): the truncated Baker-Campbell-Hausdorff formula yields an equivalence between the categories of 2-nilpotents Lie algebras over $\mathbf{Z}/p\mathbf{Z}$ and 2-nilpotents groups of exponent dividing $p$. In the free 2-nilpotent Lie algebra $\mathfrak{f}$ on generators $X\_1\dots,X\_n$ (and over any field), the ideal generated by $X\_1,\dots,X\_k$ is spanned by $X\_1,\dots,X\_k$ and $[X\_i,X\_j]$ for $i\le k$ and $j\le n$; its intersection $W\_k$ with $[\mathfrak{f},\mathfrak{f}]$ thus has dimension $f(k)=k(k-1)/2+k(n-k)$. Note that by construction, $f(k-1)+1\le
 f(k)$ for all $1\le k\le n-1$, because $[X\_{k},X\_{k+1}]\in W\_k\smallsetminus W\_{k-1}$. In particular, $f(k)<f(n)=\dim(\mathfrak{f})$ whenever $k\le n-2$, and $f(k)+s\le f(k+s)$ whenever $0\le k\le k+s\le n$. Now consider a subspace $V$ of dimension $m$ in $\mathfrak{f}$. Let $s$ be the dimension of its intersection with the derived subalgebra $[\mathfrak{f},\mathfrak{f}]$ and $k=m-s$, so $k$ is the dimension of the projection to the abelianization. Then up to an automorphism of the $\mathfrak{f}$, we can suppose that $V$ contains $X\_1,\dots,X\_k$, and hence if generated by those elements and $s$ elements of the derived subalgebra. So the ideal generated by $V$ has dimension $\le f(k)+s$, which is $\le f(k+s)=f(m)$ as we have seen. Thus if the ideal generated by $V$ contains $[\mathfrak{f},\mathfrak{f}]$ then $f(m)=n$, which implies $m\ge n-1$; in other words, the quotient of $\mathfrak{f}$ by any ideal generated by $\le n-2$ elements is non-abelian (of course it's optimal since killing $n-1$ canonical generators yields a 1-dimensional Lie algebra). 


All these facts carry over to the group, because the equivalence of categories is the identity on the underlying sets: namely given odd $p$ and an 2-nilpotent $p$-group, there is a canonically defined addition and Lie algebra law yielding the group law by the Baker-Campbell-Hausdorff formula $(gh=g+h+(1/2)[g,h])$ and Lie subalgebras (resp ideals) coincide with subgroups (resp. normal subgroups), so the minimal number of generators in either sense is the same as a group or subalgebra, resp. as a normal subgroup or ideal. Of course another approach is to convert the previous proof to the group setting, which should not be hard, and would allow to encompass the case of 2-groups.


