Here are some other historical questions that user 69268 could ask:
How was Ninevah, capital of the mighty Neo Assyrian Empire, captured and destroyed by the revolting Medes, Persians, Babylonians, Chaldeans, Scythians, and Cimmerians in 612 BC?
How was Babylon, capital of the mighty Neo Babylonian Empire, captured by the Persians in 539 BC?
How as Persepolis, capital of the mighty Persian Empire, captured and destroyed by the Macedonians and Greeks in 330 BC?
How did Rome get sacked by the Visigoths in 410 and the Vandals in 455? Rome had never been captured by foreign forces since the Gauls in about 390 BC, about 800 years before AD 410.
How did Constantinople, "this city of the world's desire", get sacked by the Fourth Crusade in 1204 after beating off many besieging forces since it was founded 874 years earlier in 330?
How was Ctesiphon, a great and wealthy city, capital of the mighty Persian Empire of the Sassanid Dynasty, captured and sacked by the Arabs in 637?
How was Chang'an, the largest city in the world, capital of the mighty Tang dynasty of China, captured and briefly occupied by the An Lushan rebels in 756 and by Tibetan forces in 763?
How was Tenochtitlan, one of the largest and most splendid cities in the world, and possibly the largest in the western hemisphere, capital of a powerful realm, captured and destroyed during the fighting by Cortes and a relatively small force of Spanish and their native allies in 1521?
How was Vijayanagara, one of the largest cities in the world and capital of the mighty Vijayanagara Empire, captured by the Deccan Sultanates, looted, burned, and its population enslaved and massacred, in 1565?
Such events do happen, and in each case there is a complicated specific situation and series of events that explain how those cities were captured by their enemies.
Assuming that Ayutthaya, capital of a large and powerful country, could not be captured by its enemies is foolish, as many capitals of larger and more powerful states have been captured by their enemies.