We do this all the time for our son who is diabetic and it has not counted as a carryon. Of course, for him food is "medicine" as his pediatric endocrinologist says.
But since food service is so limited on most flights these days, I thought airlines weren't counting food for anyone against the carryon limit. Perhaps that depends on the airline.