At first, let me tell you the reason for the rotation. As I have mentioned in the picture, the lone pair on Nitrogen can contribute to two different resonance structures. One of the resonances leads to the aromaticity of the ring which I have mentioned with number 2. This aromaticity makes the compound more stable ( lowers the energy of the molecule ). But the fact is that both resonance structures contribute to hybrid structure.
Thermodynamically, it is more likely for the compound to only have the resonance which makes the ring number 2 aromatic, Though ring number 1 rotates to prevent the lone pair on Nitrogen from having the resonance form which I have drawn with blue color. The red resonance can't be done, because after rotating, ring 1 and ring 2 are not in the same plan anymore. So because of the rotation, the more likely resonance structure will contribute to the hybrid structure more than before.
Now your question. Why does this rotation minimize the overall dipole moment?
As a result of the resonance structure ((the red one )), there will be a negative charge on Oxygen. This negative charge causes a dipole moment which is directed toward the Oxygen. Though according to picture 4, the molecule will have a smaller overall dipole moment.