Reaction of urea and thiourea with nitrous acid
As implied in your link, the reaction of urea and nitrous acid will follow the mechanism you posted, repeating a second time with the nitrogen on the remaining amide. As for why the nitrogen is more nucleophilic, I can speculate, but I don't want to be wrong.

The difference for thiourea is that sulfur can also act as a nucleophile instead of the nitrogen in the thioamide. The product is dependent on the pH. You can read more about it here. Here is the mechanism:



That's a thiourea that I squeezed in on the far right as a product from the strong acid. Sorry for the mess.