First of all, the Prophet ﷺ always chose between hot and cold to maintain balance, much like today when one seeks balance between proteins, fats, and carbohydrates. In the time of the Prophet ﷺ, people used the Greek theory, which had spread throughout the world and reached the Persians, who understood and applied it, and from there it reached the Arabian Peninsula.
This ancient theory used the humors, the colors, hot and cold, and we find it in the books of Ibn Sina (Avicenna), or Ibn Rushd (Averroes).