The independent coordinates (on the cotangent bundle of the configuration space) for describing the Hamiltonian are $(\theta,\phi,p_{\theta},p_{\phi})$. So, almost by definition, $\frac{\partial (\text{one of these four guys})}{\partial(\text{one of the three other guys})}=0$, in particular, $\frac{\partial p_{\phi}}{\partial\theta}=0$. The reason you're getting confused is you're overloading the same symbols (namely $p_{\theta}$ and $p_{\phi}$) to have two different meanings. On the one hand, you write the common but muddled equation, $p_i=\frac{\partial L}{\partial \dot{q}^i}$, so this seems to be a function of $q,\dot{q}$, and on the other hand, we have to use $(\theta,\phi,p_{\theta},p_{\phi})$ as a coordinate system, and it is this double usage which confuses you.
A single Variable Analogue.
Suppose $I,J\subset\Bbb{R}$ are open intervals, and $E:I\to\Bbb{R}$ is a given smooth function, $\Phi:I\to J$ a given diffeomorphism (smooth map with smooth inverse), and define $H:J\to\Bbb{R}$ as the mapping $H:=E\circ\Phi^{-1}$. For the sake of concreteness, let us take
- $I=\Bbb{R}$, $J=(0,\infty)$,
- $E:\Bbb{R}\to\Bbb{R}$ the function $E(x)=x+e^x$,
- $\Phi:\Bbb{R}\to (0,\infty)$ the diffeomorphism $\Phi(x)=e^x$, so $\Phi^{-1}:(0,\infty)\to\Bbb{R}$ is $\Phi^{-1}(y)=\log(y)$.
- $H:(0,\infty)\to\Bbb{R}$ is then the defined as $H=E\circ\Phi^{-1}$, which yields $H(y)=(\log y) + y$.
If I now ask you to compute the derivative $H'(y)$, you'll immediately tell me that since $H(y)=\log y + y$, then $H'(y)=\frac{1}{y}+1$, and there's no doubt about it. Notice that there's nothing special about the letters $x$ and $y$. If I wanted to, I could say $E(t)=t+e^t$, and $H(t)=(\ell\circ\Phi^{-1})(t)=\log t + t$. This is perfectly correct mathematically.
Now, this same procedure is typically presented in physics texts without introducing
a name for the diffeomorphism $\Phi$. It is typically presented as saying:
Consider the function $E(x)=x+e^x$, and make the change of variables $y=e^x$ to get a function $H(y)$. This function equals, $H(y)=\log y + y$, so $H'(y)=\frac{1}{y}+1$.
Notice that there is still an overload of notation in this description! The same symbol $y$ is first being used in place of the diffeomorphism $\Phi$, and second it is used as the argument of the function $H$. It is just that one might be too comfortable with single-variable calculus that they gloss over the notational overload.
In any case, the bottom line is once you make the change of coordinates (i.e composing by $\Phi^{-1}$), you should forget about whatever happened before (i.e the $x$-coordinates).
The Original Question, in Modified Notation.
What I described above is exactly what we're doing when we change from Lagrangian to Hamiltonian mechanics. We start with an energy function $E:\Bbb{R}^{2n}\to\Bbb{R}$ in Lagrangian mechanics (here $n=2$), and use a diffeomorphism $\Phi$ between open subsets of $\Bbb{R}^{2n}$ (this is the Fiber derivative of the Lagrangian, $\mathbf{F}L:TQ\to T^*Q$ in fancy differential geometry jargon), and using this we 'change coordinates' to get the Hamiltonian $H:=E\circ\Phi^{-1}$.
What follows might be slightly difficult to read initially because I'm going to use non-standard letters to denote the independent variables, but hopefully after this you'll appreciate the difference between the choice of coordinates and the diffeomorphism used.
The Lagrangian. This is a function $L:\Bbb{R}^4\to\Bbb{R}$, given as
\begin{align}
L(x_1,x_2,y_1,y_2)&=\frac{ml^2}{2}\left(y_1^2+\sin^2(x_1)y_2^2\right)+ mgl\cos(x_1).
\end{align}
Compared with the standard notation, here I used $(x_1,x_2,y_1,y_2)=(\theta,\phi,\dot{\theta},\dot{\phi})$.
The choice of letters is of course insignificant, I can also write something like $L(a,b,c,d)=\frac{ml^2}{2}\left(c^2+\sin^2(a)d^2\right)+ mgl\cos(a)$.
The Energy. This is the function $E:\Bbb{R}^4\to\Bbb{R}$ defined as
\begin{align}
E(x_1,x_2,y_1,y_2)&=y_1\frac{\partial L}{\partial y_1}\bigg|_{(x_1,x_2,y_1,y_2)}+
y_2\frac{\partial L}{\partial y_2}\bigg|_{(x_1,x_2,y_1,y_2)} - L(x_1,x_2,y_1,y_2)\\
&=y_1\cdot ml^2y_1 + y_2\cdot ml^2\sin^2(x_1)y_2
-\bigg( \frac{ml^2}{2}\left(y_1^2+\sin^2(x_1)y_2^2\right)+ mgl\cos(x_1)\bigg)\\
&=\frac{ml^2}{2}\left(y_1^2+\sin^2(x_1)y_2^2\right)- mgl\cos(x_1).
\end{align}
The Fiber Derivative. This is the mapping $\Phi:\Bbb{R}^4\to\Bbb{R}^4$, defined as
\begin{align}
\Phi(x_1,x_2,y_1,y_2)&:=\left(x_1,x_2, \frac{\partial L}{\partial y_1}\bigg|_{(x_1,x_2,y_1,y_2)}, \frac{\partial L}{\partial y_2}\bigg|_{(x_1,x_2,y_1,y_2)}\right)\\
&=\bigg(x_1,x_2, ml^2y_1, ml^2\sin^2(x_1)y_2\bigg).
\end{align}
This map becomes a diffeomorphism if we restrict the domain and target sufficiently, in which case, the inverse map is
\begin{align}
\Phi^{-1}(\xi_1,\xi_2,\eta_1,\eta_2)&=\bigg(\xi_1,\xi_2,\frac{\eta_1}{ml^2},\frac{\eta_2}{ml^2\sin^2\xi_1}\bigg).
\end{align}
The Hamiltonian. This is the composed mapping $H:=E\circ \Phi^{-1}$. So, after some computation,
\begin{align}
H(\xi_1,\xi_2,\eta_1,\eta_2)&=E(\Phi^{-1}(\xi_1,\xi_2,\eta_1,\eta_2))\\
&=\dots\\
&=\frac{\eta_1^2}{2ml^2}+\frac{\eta_2^2}{2ml^2\sin^2\xi_1}-mgl\cos\xi_1.
\end{align}
Now, in the Lagrangian, we have $\frac{\partial L}{\partial x_2}=0$, so we expect that for the Hamiltonian side, $\{\eta_2,H\}=0$, and indeed, we can verify this is the case:
\begin{align}
\{\eta_2,H\}&=\left(\frac{\partial \eta_2}{\partial \xi_1}\frac{\partial H}{\partial \eta_1}- \frac{\partial \eta_2}{\partial \eta_1}\frac{\partial H}{\partial \xi_1}\right)
+
\left(\frac{\partial \eta_2}{\partial \xi_2}\frac{\partial H}{\partial \eta_2}- \frac{\partial \eta_2}{\partial \eta_2}\frac{\partial H}{\partial \xi_2}\right)\\
&=0-0+0-\frac{\partial H}{\partial \xi_2}\\
&=0,
\end{align}
since the partials of $\eta_2$ with respect to the other coordinates $\xi_1,\xi_2,\eta_1$ are trivially $0$, while $\frac{\partial\eta_2}{\partial\eta_2}=1$ and finally since $H$ doesn't depend on $\xi_2$.
If you want to compare notation, then $(\xi_1,\xi_2,\eta_1,\eta_2)=(\theta,\phi,p_{\theta},p_{\phi})$. Anyway, the takeaway is that you need to distinguish between the coordinates used to describe the Lagrangian/Hamiltonian, and the diffeomorphism $\Phi$ which allows you to convert between the two formalisms.