Well, theta is a state variable while H is a input variable. Usually, the potential energy U is a function of only the state variables - (r,theta,phi) - in spherical coordinate system - for the simplified case it's only a function of theta. It's valid for only a 'closed' system.
If some...
Say, we have potential energy of the form U = cos (\theta(t)) H(t).
H denotes a magnetic field that is time-dependent and it's an input variable to the system. Now when you take gradient of potential energy, would you write
\nabla U = \left[ - sin (\theta(t)) H(t) + cos (\theta(t))...