It was hard to find a source.
On Yom Kippur, cooking will be forbidden because work is forbidden.
However, from here I see that
the gemoro in Shabbos 115a says that although generally it is
prohibited to prepare on a Shabbos or Yom Tov for afterwards, even if
not melacha is being violated, there was an exemption made for קניבת
הירק in the late afternoon of Yom Kippur. There is a machlokes what
exactly קניבת ירק means. Rashi says it refers to the removal of the
leaves to prepare the vegetables to be cut and sliced after the fast.
The Shulchan Aruch 611:2 writes
וְהִתִּירוּ לְקַנֵּב יָרָק וְלִפְצֹעַ אֱגוֹזִים מִן הַמִּנְחָה
וּלְמַעְלָה, כְּשֶׁחָל בַּחֹל, וְהָאִדָּנָא נָהֲגוּ לֶאֱסֹר
that technically kenivas hayerek and cracking nuts is permitted from
the time of mincha and onwards but nowadays the minhag is to forbid
The reason to forbid it is, as we see from the end of the gemara, that people started to be lax and made the preparations prior to mincha.
So we see that essentially preparation of food even on Yom Kippur late in the day is permissible.
On Tisha B'Av Ohr Someach says that
Washing for cooking or for medical reasons is permitted.
Things that divert one from mourning such as idle talk, reading the
newspaper, taking a walk for pleasure, etc. are prohibited.
The custom is to refrain until midday from any time-consuming work
that diverts one from mourning.
On other fast days, I found the following question at moreshet.co.il
אם אנשים שלא צמים מבקשים ממני ביום הצום כוס שתיה (דבר שיכול לקרות
במקום העבודה), כיצד עלי לנהוג ?
If people who are not fasting ask me to prepare them a drink on a fast
day (which can happen in the workplace) what should I do?
Rav Avrohom Yosef answers:
למי שאינו צם מחמת חולי, או סיבה מוצדקת מותר להכין
For someone who is not fasting for reasons of illness or some other
legitimate reason, it is permitted to prepare the drink.
So we see that essentially preparation of food even on Yom Kippur late in the day is permissible. On other fast days, it is permitted for people not fasting.
On Tisha B'Av cooking is allowed as long as it does not take one's mind away from the mourning.
I think that if you add these items together, you can conclude that it will be permissible to prepare food on a fast day (other than YK) for others at any time and for oneself near to the end of the fast.