If a person purposely cooked on Shabbos, he cannot benefit from that food ever.
Question: Can he give that food to another for mishloach manos, since (1) the other person is allowed to eat it and (2) the mitzvos were not given for our benefit?
This is an interesting question.
The Rav Pe’alim (Vol. 3, Orach Chaim 17) explains that if somebody cooks on Shabbos intentionally, the food is prohibited in deriving benefit, and it cannot be sold or given as a gift. This is because even giving something as a gift involves derivation of benefit.
Mishloach Manos is a mitzvah, and therefore there is room to suggest, as you do in the question, that this is not considered “benefit” and it would be permitted to give the Mishloach Manos from food cooked on Shabbos.
Yet, there is room to argue that it will not be permitted to use the food for Mishloach Manos, for two reasons:
1. Shut Ha-Elef Lecha Shlomo (Choshen Mishpat 8) writes that it is not permitted to pay one’s debts with Issurei Hana’a. The reason is that this will involve a direct monetary gain, since the mitzvah is to pay money, and this is not included in the principle of “mitzvos lav lihanos nitnu.” The same will apply for Mishloach Manos. The principle of the Ha-Elef Lecha Shlomo does not appear to be agreed upon by all authorities (see for instance Shut Machaneh Chaim, 1:23) but this will be one reason for stringency.
2. It is sufficient to give a small amount for Mishloach Manos, and there is no need to give the entire dish. Therefore, it can be argued that all of the “surplus food” that is given is not part of the mitzvah but only an “addition” onto the actual mitzvah, so that it will not be included in the idea of mitzvos lav lilhanos. This can be disputed however, and it depends on the general sugya of “marbeh beshiurim.”
The answer to this question therefore remains to be debated.