Where is this counterterm coming from? Given the Lagrangian in 6-dimensional spacetime:
$$
L = \frac{1}{2}\partial^\mu\phi\partial_\mu\phi - \frac{1}{2}m^2\phi^2-\frac{g_3}{3!}\phi^3.\tag{1}
$$
The Lagrangian with counterterms is given by
$$
L_c = \frac{1}{2}Z\partial^\mu\phi\partial_\mu\phi - \frac{1}{2}(m^2+\delta_m^2)\phi^2\color{red}{-Z_1g_1\phi}-Z_3\frac{g_3}{3!}\phi^3\\
= \frac{1}{2}\partial^\mu\phi\partial_\mu\phi - \frac{1}{2}m^2\phi^2-\frac{g_3}{3!}\phi^3 +\frac{1}{2}(\partial^\mu\phi\partial_\mu\phi)\delta_z-\frac{1}{2}\delta_m^2\phi^2\color{red}{-\delta_1\phi}-\delta_3\frac{\phi^3}{3!}.\tag{2}
$$
How does the term $\color{red}{-Z_1g_1\phi}$ and $\color{red}{-\delta_1\phi}$ appear? The superficial degree of divergence of a graph in 6 dimensions could be found as
$$
\omega = 6-2n\tag{3}
$$
where $n$ is the number of external lines. To find the one-particle irreducible divergent graphs, we can set $n = 1,2,3$. It seems to me that those terms in the Lagrangian are associated with the $n=1$ case.
However, for $n = 2$ and $3$, it's more clear to me where the counterterms come from, because $\delta_m$, $\delta_z$, and $\delta_3$ are 'attached' to some existing quantities. I don't know how to understand why  $\color{red}{-Z_1g_1\phi}$ and $\color{red}{-\delta_1\phi}$ are added to the Lagrangian.
Also, I'm not confident with implementing $Z$ factors. I would really appreciate it if someone could explain a bit about the first line of $L_c$. Why and how the $Z$ factors are attached?
 A: The linear term has to be included to cancel tadpole diagrams, AKA diagrams with one external leg and its embedded variants in more complicated diagrams. For $\phi^3$ you've got the $O(\lambda)$ term $$-i\delta_1-\frac{i\lambda}{2}\int d^dk \ \frac{i}{k^2-m^2+i\epsilon}$$ which has to be set to zero by tuning $\delta_1$. The problem is not only that this term is divergent, but also the fact that the LSZ theorem requires a zero vaccum expectation value to project out the correct particle states.
The factors of $Z$ and $\delta$ in your Lagrangian are there to make your Lagrangian depend on the regulator parameter ($\Lambda$, $\epsilon$, $a$ depending on your regularization scheme) so that they can be made to cancel the divergent quantities in observables when the physical limit is taken (e.g. $\Lambda\to\infty$).
A: There is already a correct answer by AfterShave. The point is that one must for consistency as a minimum include all possible renormalizable terms that are not excluded by symmetry, such as a tadpole term $Z_1g_1\phi$, cf. the totalitarian principle, even if they were absent at some scale.  Perhaps this is most easily seen from the perspective of the Wilsonian effective action, cf. my Phys.SE answer here.
For other examples, see e.g. this & this related Phys.SE posts.
