The main source of ammonia in koi ponds is fish metabolism. Metabolism is a general term covering all the various processes taking place in living organisms, such as food digestion, energy production, tissue repair and cell growth. During this process, complex food structures are broken down into simple amino acids (from proteins), carbohydrates and fats and reformed according to the fish's needs. Any surplus is stored as body fat or excreted as waste. Excess amino acids cannot be stored and end up being converted to ammonia in a process called deamination and then excreted into the water via the gills. Any undigested food is passed out with the faeces. This process is not exclusive to fish, indeed all animals produce metabolic ammonia. However, in most animals ammonia is immediately converted into a less toxic substance, usually urea, and excreted in the urine.
In the case of fish, Mother Nature decided that the large volumes of water in oceans, lakes and rivers would adequately dilute the harmful ammonia - but obviously no one told her about koi ponds! Koi, being voracious eaters, produce large amounts of ammonia and may be considered as ammonia factories, converting expensive fish food into ammonia and other wastes. The amount of ammonia produced is directly related to the amount of food given each day, which of course depends on the stocking level and size of fish.
Further sources of ammonia are decomposing fish wastes, undigested fish food and other organic matter. When such matter decomposes, it is broken down by bacterial and fungal action into simple compounds. This process is called mineralisation. A whole host of organic products, including ammonia, are produced during decomposition, which is why rotting matter always smells so awful.