Arenediazonium compounds contain a very good leaving group - nitrogen gas - and thus undergo nucleophilic substitution reactions rapidly. With water, for instance, they give phenols.
In the formation of azo dyes from arenediazonium salts, however, the arenediazonium cation acts as an electrophile to carry out a substitution reaction on activated benzene rings like those of phenols and anilines. Why doesn't displacement of $\ce{N2}$ happen here as well? Normally the carbon attached to $\ce{-N2+}$ acts as the electrophilic centre, so phenols and anilines should react at that $\ce{C}$ rather than at the $\ce{-N2+}$ group. Moreover, phenols and anilines have more nucleophilic centres at their $\ce{O}$ and $\ce{N}$ than at the carbon atoms of their benzene ring - so why aren't the final products be diphenyl ether with phenol, and N-phenylaniline with aniline?