Why is it so that azo coupling with phenol needs basic pH (9–10) and with aniline it needs acidic pH (4–5). How does pH participate in the mechanism? I have searched the internet for quite a while nowhere does it explain the actual ‘role’ of the pH. Any light on this matter would be helpful.
Deprotonation of the phenol and protonation of aniline result in species that easily react with a diazonium cation in the intended manner.
Let's have a look at the species involved. On the one hand, there is the diazonium cation:
Deprotonation of phenol yields phenolate, for which a resonance structure with a negative charge in para position to the substituent can be written:
We conclude: Deprotonation of the phenol means activation!
In the case of aniline, the lone pair on the nitrogen atom is the preferred centre for the reaction with the diazonium cation:
This isn't what we want! Protonation of aniline avoids this side reaction.
We conclude: Protonation of aniline means "masking" the wrong centre!