For the bob to execute pendulum like motion, that is to say circular motion about the point of the contact of the string with the ceiling, then it must have a net non zero radial force acting upon it which provides the necessary centripetal force. If this radial force is brought to zero, then the mass moves in a straight line. It is zero for small time at the 'edge' of the swing, its angular speed vanishes here but the circular motion is maintained because of the restoring force $-mg \sin \theta \hat \theta$.
The work done on the bob is given by $W = \int \mathbf F \cdot \mathbf{dr}$, where $\mathbf F = F_r \hat r + F_{\theta} \hat \theta$ and equal to $ (-T + mg \cos \theta) \hat r - mg \sin \theta \hat \theta$, as you wrote. For a general circular motion, the infinitesimal line element that the bob moves along can be expressed in polar coordinates as $\mathbf{dr} = \ell d \theta \hat \theta$, where $\ell$ is the length of the string. So the radial force thus does no work and the computation of the work reduces to $$W = \ell \int_{\theta_0}^{\theta} F_{\theta'}\, d \theta' = -mg \ell \int_{\theta_0}^{\theta} \sin \theta' \, d\theta' = mg \ell (\cos \theta - \cos \theta_0) $$ This is work done by a gravitational force so $\phi(\theta) = -W = mg \ell (\cos \theta_0 -\cos \theta)$.
Reply to $\mathbf{comment2}$:
Consider subtending the bob some angle $\theta_{\text{max}}$ from the vertical and releasing it. At the bottom of the swing, $T(\theta) - mg = m v^2 (\theta)/\ell$ which is to say the tension is greatest here. At an arbitrary point in the motion though, for circular motion to persist, we must have $$T(\theta) - mg \cos \theta = mv^2(\theta)/\ell. \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,(1)$$ As the bob passes through the bottom point of its swing and is on its way back up to $\theta_{\text{max}}$, the value of $mg \cos \theta$ will decrease which means $T$ must decrease too to preserve $(1)$ (remember there is a relative minus sign between the two terms). We must have a $|\mathbf T | > |m \mathbf g \cos \theta |$ throughout the circular motion so that there is a net radial force directed inwards but, at some point, since both $mg\cos \theta$ and $T$ are decreasing, they will equilibrate and cancel each other out.
This corresponds to the end of the circular motion, which by conservation of energy must occur at $(\pm) \theta_{\text{max}}$. In dissimilarity, $m\mathbf g \sin \theta$ is largest here and directed downwards and thus drives the mass back to execute further circular motion. It is perhaps easier to visualise all these arguments by drawing the net acceleration vectors throughout the motion.
Reply to $\mathbf{comment1}$:
The radial force allows the mass to keep turning so to speak. Break the circular path up into small tangential segments. If we suddenly bring this force to zero then the bob will leave the circular path and follow in the path of the last (straight) tangential segment it was on - it had some velocity before this happened so it will continue to move like this before gravity distorts its path. This is just a consequence of Newton's first law.