It's even less logical than that:
Why is it "im Juli und August" and not "im Juli und dem August"? In other words, why does July take an article while August does not?
In English, you sometimes can use a single "the" article for a list of things following it (e.g. "the sons and daughters..."), but even that logic would be problematic in German: while in English, there is no distinct plural form of "the", there is one in German. In other words, "dem" in the construction "im Juli und August" is clearly singular and hence cannot refer to both July and August. Otherwise it would have to be ""in den Juli und August" (with "den" being the dative form of the plural "die").
My only explanation is that using "im" with the months' names is one of those otherwise nonsensical things that got "stuck" in the language for some historical reasons. A learner should just memorise it; in most other cases the months names don't take articles just as they would not in English. E.g., DL has already given us a construction "zwischen Juni und August" -- no articles there!
"Im Juli und August" can take only one article because both of the nouns are the same gender, and "Juli und August" are (sort of) acting as a single unit here, so they're both sharing the same article. A comparable example in English might be "the rain and snow" which are both sharing the same article.
Secondly, it doesn't take the plural article "den" because neither Juli nor August are in the plural. Listing multiple singular nouns is not the same thing as a plural. If you said "den Juli und August", then this would likely be interpreted as being an accusative singular, but if we just pretend for a minute that someone were to interpret this in a plural sense, then that would be like saying "The Julies and Augusts." Referring to more than one noun is not a plural, it's just referring to more than one noun. It makes perfect sense, and it's quite clear.
Lastly, your example of "zwischen Juli und August" might not be referring to a specific period between July and August, but rather to just every period between July and August in general. Duolingo has this habit of not providing any context, so it's hard to say for sure. But as far as I understand it, generalizations don't take articles. So with an article, you might say something like "(I will see you) zwischen der Juli und August", as you're referring to a period of time between a specific July and a specific August (presumably, the upcoming July/August) (EDIT: Scratch that. It just occurred to me that "zwischen" is a two-way preposition, and this sentence has no movement from one location to another, and so it would actually still take the dative. My bad). Without the article, you might say something like "(It tends to be rather warm) zwischen Juli und August", as this time, you're not talking about a period of time between a specific July and a specific August, but rather just between all Julies and all Augusts in general.
As for the sentence in this particular exercise which we're commenting on "Jährlich im Juli und August", maybe we're talking about something specific within the broader context of the conversation. I can't really say for sure. Or maybe this conversation is about some kind of action which doesn't involve movement from one location to another, and therefore takes dative in order to specify that. I imagine it's probably possible to get "in" instead of "im" in this sentence supposing the context were right for it.
I'm definitely not a native speaker though, so if I'm mistaken about any of this, then may a native speaker please feel free to correct me, and I will promptly place my foot directly into my mouth. lol. =3
I feel that something is unclear in your explanation. The conjunction "and", in this case, as well as lists of particular singular nouns often indicate plurality which is clearly seen in such cases as "Juli und August sind Monate" or "Wasser und Milch sind Getränke.
I searched it up, and according to this source, basically, articles are relative to the gender and plurality of individual nouns in such a case rather than the overall plurality. In some cases, the article is only required for the first noun, and in other cases it is required for all nouns. See more: https://german.stackexchange.com/questions/18903/agreement-of-articles-with-lists-of-nouns
August does take article, but the articles in Deutsch are usually ommited not to be repeated. Unfortunately, I couldn't find any source for that, but someone have once told me that.
Well, if you speak of zwischen which doesn't take articles that's indeed an exclusion. Usually it does require articles. Nevertheless I think it's not that big problem, because zwischen is mostly used not with dates, rather with physical objects. Perhaps it was Duo's mistake.
And last but not least, there are lot of cases when article is omitted in English too.
In English 'yearly' or 'annually' implies exactly once a year, while 'in July and August' implies covering two months, which together would mean in English the implication is that this describes an event which happens every year from some point in July to some point in August. Is this the same meaning as in the German, or could the German "Järhlich im Juli und August" also mean "twice a year, once in July, and once in August"?
I realize it's a very fine nuance of the meaning, but I'm trying to get a finer understanding of the language.