The above stated reaction is an example of electrophilic aromatic substitution. In alkaline medium, phenol generates phenoxide. ion which is more electron rich than phenol and more reactive towards electrophilic attack.
The electrophile in this reaction is aryldiazonium cation. As we know, stronger the electrophile faster is the reaction, p-nitrophenyldiazonium cation is a stronger electrophile than p-toluene diazonium cation.