  We investigate the spin state of a protoplanet during the pebble accretion
influenced by the gas flow in the gravitational potential of the protoplanet
and how it depends on the planetary mass, the headwind speed, the distance from
the host star, and the pebble size. We perform nonisothermal three-dimensional
hydrodynamical simulations in a local frame to obtain the gas flow around the
planet. We then numerically integrate three-dimensional orbits of pebbles under
the obtained gas flow. Finally, assuming uniform spatial distribution of
incoming pebbles, we calculate net spin by summing up specific angular momentum
that individual pebbles transfer to the protoplanet at impacts. We find that a
protoplanet with the envelope acquires prograde net spin rotation regardless of
the planetary mass, the pebble size, and the headwind speed of the gas. This is
because accreting pebbles are dragged by the envelope that commonly has
prograde rotation. As the planetary mass or orbital radius increases, the
envelope is thicker and the prograde rotation is faster, resulting in faster
net prograde spin. When the dimensionless thermal mass of the planet, $m =
R_{\mathrm{Bondi}} / H$, where $R_{\mathrm{Bondi}}$ and $H$ are the Bondi
radius and the disk gas scale height, is larger than a certain critical mass
($m \gtrsim 0.3$ at $0.1 \, \mathrm{au}$ or $m \gtrsim 0.1$ at $1 \,
\mathrm{au}$), the spin rotation exceeds the breakup one. The predicted spin
frequency reaches the breakup one at the planetary mass $m_{\mathrm{iso,rot}}
\sim 0.1 \, (a / 1 \, \mathrm{au})^{-1/2}$ (where $a$ is the orbital radius),
suggesting that the protoplanet cannot grow beyond $m_{\mathrm{iso,rot}}$. It
is consistent with the Earth's current mass and could help the formation of the
Moon by a giant impact on fast-spinning proto-Earth.
