As you have read, the Aztecs practiced human sacrifice. Most of the people sacrificed were not residents of the Aztec's major cities, rather they were captured in wars, both wars of conquest and wars of the flowers. The Aztec term for wars for captives was Xochiyayoyotl.
The Xochiyayoyotl came about after a long famine, from 1450 to 1454. Crops failed all over the Valley of Mexico due to bad weather. To the Aztecs, it showed the gods were displeased; they needed more blood and human hearts. Montezuma I reigned during the great famine. His brother Tlacaelel was Montezuma's Snake Woman or first adviser, a general in the Aztec army and of the highest warrior order, the Shorn Ones.
When bad weather continued the famine, Tlacaelel suggested a ritual or ceremonial war to provide captives for sacrifice for the Aztecs and their enemies. The nearby Tlaxcala were the Triple Alliance's main enemy. They had also experienced the famine. Through human sacrifice, the gods would be assuaged for both sides.
Though there were undoubtedly more reasons for Flower wars, such as further terrorizing the surrounding areas, they began during the great famine. Tenochtitlan reached an agreement with its enemies the Tlaxcala, Cholula and Huejotzingo, to war for captives. Their warriors would be told not to kill enemy warriors, but to capture them. Once each side had enough captives, the battle would end. The captured warriors would then be taken for sacrifice by both sides in the battle.
Thus, from time to time, Aztecs would arrange a Flower war when the need for human captives arose. In essence, these were ceremonial in nature, with all the details arranged beforehand by the leaders involved. Nevertheless, they were still a matter of life and death for the warriors; to be captured meant being sacrificed. While a sacrifice was considered an honorable death, no doubt most warriors would prefer to avoid it.
Whether a Flower war was arranged simply to satisfy religious demands for sacrificial victims, to train young warriors and to ensure social advancement for warriors or if it had underlying purposes of wearing down the enemy and terrorizing neighboring lands is still debated by scholars.
Some scholars maintain that the Flower wars were more like tournaments, with no more political purpose than to satisfy warriors in vying for advancement and provide ritual bloodletting and sacrifices. Other scholars see darker political aspects to these ritual wars: to demonstrate Aztec might, to wear down the enemy through attrition and to allow Aztec leaders to subjugate their own people through fear of losing loved ones.
The Aztecs had never managed to conquer the Tlaxcala. While the Tlaxcala were also Aztecs, they refused to pay tribute to the Triple Alliance. Montezuma might have thought that through the Flower wars, the Triple Alliance would be able to wear down the Tlaxcala and capture more of their warriors than they could afford to lose. If so, the Tlaxcala delivered the final blow: they allied with the Spanish in conquering and defeating the Aztec Empire.