Why the 9th of Av?

תענית כ״ט א

אי אפשר לומר בשבעה שהרי כבר נאמר בעשור ואי אפשר לומר בעשור שהרי כבר נאמר בשבעה

הא כיצד?

בשבעה נכנסו נכרים להיכל ואכלו וקלקלו בו שביעי שמיני ותשיעי סמוך לחשכה הציתו בו את האור והיה דולק והולך כל היום כולו שנאמר (ירמיהו ו, ד) אוי לנו כי פנה היום כי ינטו צללי ערב והיינו דאמר רבי יוחנן אלמלי הייתי באותו הדור לא קבעתיו אלא בעשירי מפני שרובו של היכל בו נשרף ורבנן אתחלתא דפורענותא עדיפא

Taanit 29a

"It is impossible to say the seventh [was the true date of the destruction], for already it was said about the tenth; and it is impossible to say the tenth [was the true date], for already it was said about the seventh.

How [do we resolve this contradiction]?

On the seventh, gentiles entered the Sanctuary, and they ate and befouled it on the seventh, eighth, and ninth. close to nightfall [on the ninth], they set upon it the fire, and it burnt continuously all the entire day... And this is [the reasoning] that Rabbi Jochanan said, "If I had been in that generation, I would not have established it [on the ninth] but rather on the tenth, because most of the Sanctuary was burnt on it." And the Rabbis [reasoning was that] the earliness of suffering was preferred.

Shulchan Aruch, Orach Chayim 558:1

בְּתִשְׁעָה בְּאָב לְעֵת עֶרֶב הִצִּיתוּ אֵשׁ בַּהֵיכָל וְנִשְׂרַף עַד שְׁקִיעַת הַחַמָּה בְּיוֹם עֲשִׂירִי, וּמִפְּנֵי כָּךְ מִנְהָג כָּשֵׁר שֶׁלֹּא לֶאֱכֹל בָּשָׂר וְשֶׁלֹּא לִשְׁתּוֹת יַיִן בְּלֵיל עֲשִׂירִי וְיוֹם עֲשִׂירִי. הַגָּה: וְיֵשׁ מַחְמִירִין עַד חֲצוֹת הַיּוֹם וְלֹא יוֹתֵר (הַגָּהוֹת מַיְמוֹנִי); אִם חָל תִּשְׁעָה בְּאָב בְּשַׁבָּת וְנִדְחָה לְיוֹם א', מֻתָּר לֶאֱכֹל בָּשָׂר וְיַיִן יוֹם ב', אֲבָל בַּלַּיְלָה אָסוּר מִפְּנֵי אֲבֵלוּת שֶׁל יוֹם (מַהֲרִי''ל).