In this case, its doublet is involved in the cycle mesomerism and there appear negative charges on ortho and para positions in the contributory structures : Examples: Phenol
The positive charge (partial, average of contributory forms) of $O$ is increasing its attractiveness on the electrons of $O-H$ bond while facilitating the departure of $ H^+$ which explains the high acidity of phenol compared to that of aliphatic alcohols
The nitrogen doublet is little available which explains the low basicity of aniline compared with aliphatic amines!
In this case, a benzene doublet tends to extend mesomerism to this atom and there appear positive charges on ortho and para positions in the contributory structures : Example: Benzoic acid
The increase in the electron density on the carbon of the carboxylic acid function pushes the electrons of the $O-H $ bond towards hydrogen and the resulting difficult departure of $H^+$ explains the low acidity compared to aliphatic carboxylic acids