The reason the Wildfire was stored underneath the city was the Mad King became... well, mad in his later years.
The wildfire plot was a plan developed by King Aerys II Targaryen during the latter stages of Robert's Rebellion.
After the rebel victory of Robert Baratheon at the Battle of the Bells, Aerys was fearful that Robert might actually win the war and enlisted the aid of several members of the Alchemists' Guild in a plot to destroy the city of King's Landing should the rebel forces prove victorious. Ser Jaime Lannister was present when this was planned, while the rest of the Kingsguard was absent and went with Crown Prince Rhaegar Targaryen.
Thousands of jars of wildfire were gathered and placed in key positions under King's Landing. Hundreds were placed under the Dragonpit and the Great Sept of Baelor, under every one of the city's gates and even under the Red Keep itself. The pyromancers did their work in secret and did not trust their apprentices with the knowledge
Jaime killed all those involved during the Sack of Kings Landing:
During the Sack of King's Landing, Aerys commanded Rossart to ignite the wildfire to destroy the city and Jaime to bring the head of his father, Lord Tywin Lannister. Jaime, however, intercepted and slew Rossart to prevent his message from reaching other pyromancers. Jaime then slew Aerys, slitting his throat. A few days later Jaime hunted and killed Garigus and Belis, the other pyromancers involved in the plot.
We only have evidence that he told two people...
- Brienne of Tarth, during their travels from the Riverlands to Kings Landing
- Tyrion, most likely during the escape from the Black Cells. Although we do not know it from seeing it on-screen.
Tyrion only found a small cache of Wildfire...