Why does ammonia "clean" scratches?
This seems more like folklore than a tested method. However, gold is extremely soft (malleable), and it must be alloyed with other metals to make it hard enough to survive wear as jewelry. Simply rubbing a gold item with a cloth, with or without "ammonia" (ammonium hydroxide, $\ce{NH4OH}$), is enough to polish the gold, i.e. relocate some gold particles to fill in the scratch.

Household ammonia does not solidify, nor will it fill scratches. In fact, it simply evaporates into the air. It is an effective cleaner, though, and would help remove anything adhered to the gold, which might appear like a scratch.

For the same reason, ammonium hydroxide is an effective glass cleaner, but don't expect it to remove any scratches. The suggestion at your second reference to use toothpaste, though, is a good idea, particularly for those brands containing silica.

BTW, "milk of magnesia", $\ce{Mg(OH)2}$, is an effective mildly abrasive scratch remover for some plastics, if rubbed very well with a soft cloth.