Well, it's all over the place as far as I can tell. And we just have to memorize the idioms and accept that they don't match English exactly.
Here's a good article that gives lots of examples of expressions involving weather: https://www.fluentu.com/blog/spanish/spanish-weather-expressions/
In Me gusta el invierno, it's the subject of the sentence (the order is just switched around compared to most sentences). As the subject there's basically a rule that says it needs the article (or some other kind of determiner).
As the object (e.g. in this sentence) there's no such rule.