What determines the geometry of Nitrogen to be planar or trigonal pyramidal?

In the following molecule (1-(4-fluorophenyl)-4-[[1-(2-methoxyethyl)tetrazol-5-yl]-phenyl-methyl]-piperazine)

I have seen its 3D structure using Jmol, and I see that both nitrogens on the middle ring have either tetrahedral or trigonal pyramidal geometry. I get this, no problem. However, the ring that is made of four nitrogens is entirely planar. Shouldn't it also have some trigonal pyramidal nitrogens too? As for instance, the N on the point connecting to the -OH chain, it has 2 bonds and one unshared pair of electrons, yet it is still planar!

• Lone pair determines that. The piperazine nitrogens have it, while the tetrazole N with side chain doesn't. – Ivan Neretin May 21 '18 at 9:29
• The simplest example for $\mathrm{sp^3} ~\ce{N}$ showing planner geometry is N-methylpurrole. – Mathew Mahindaratne May 21 '18 at 16:22
• @MathewMahindaratne Just why would that N be $sp^3$? – Ivan Neretin May 21 '18 at 16:39
• @Ivan Neretin: Then, what you'd like to call it as an answer for a question from a college student who is still going for their first degree? – Mathew Mahindaratne May 21 '18 at 18:06
• @MathewMahindaratne I'd say a college student must realize that the pyrrole N doesn't have a lone pair and hence is planar. – Ivan Neretin May 21 '18 at 18:30

You can predict the geometry around the nitrogen atom whether it is Pyramidal or trigonal planar by noting the hybridization of $\ce{N}$. If the lone pair on $\ce{N}$ atom doesn't delocalise at all i.e there are all $\sigma$ bonds and no $\pi$ bond occurrence,the hybridization remains $sp^3$ and the geometry remains tetrahedral( leaving the lone pair it is Pyramidal), but if the lone pair on $\ce{N}$ is in continuous delocalisation and there is a case of formation of $\pi$-bond, the geometry has to be planar (hybridization close to $sp^2$).
In middle ring if you observe carefully the lone pair on lower $\ce{N}$ is in continuous delocalisation with the benzene ring so its geometry will be planar, but there are all $\sigma$-bonds associated with the upper $\ce{N}$, so that has a tetrahedral geometry.
Similarly observe the tetrazole ring (ring made of four nitrogens). Draw the resonance structures of that. You will find that all the $\ce{N}$s are equivalent (forming 2 $\sigma$-bonds and $\pi$-electron cloud throughout the ring) and the ring is actually aromatic. Thus all the nitrogen atoms have to be planar for effective delocalisation.