Why does the O atom of N-phenylnitrosamine donate its lone pair towards H+ when O is more electronegative than N?
If you look at complete mechanism, this wasn't hard to understand why only oxygen get protonated instead of readily available nitrogen, which is supposedly more nucleophilic than oxygen. OP has given N-phenylnitrosamine as the direct product from reaction between aniline and nitrosonium ion, avoiding the first intermediate I (see following reaction mechanism of formation of diazonium ion). As Waylander correctly pointed out in his comment that all of these steps are reversible until you get diazonium ion (counterion $\ce{X-}$ is chloride ($\ce{Cl-}$) in this case):



As I emphasized in the Blue box of the depicted diagram, nitrosamine can be protonated on either $\ce{N}$ (see in blue box) or $\ce{O}$ (see in the total mechanism). As shown in the total mechanism, protonation is slightly favored towards $\ce{O}$ because charged intermediate is resonance stabilized. Nonetheless, this stabilized intermediate is the one directing to the expected product, diazonium salt (see also Waylander comment), making it more favorable. Also note that protonation on $\ce{N}$ make the intermediate going back to original first intermediate I, which cannot give the any other product.

Note: Also keep in mind that direct conversion from intermediate I to resonance stabilized, $\ce{O}$-protonated intermediacte can be achieved by $\ce{N}$ to $\ce{O}$ proton transfer, which is highly likely.