The Buddha who knew there were 31 realm but didn't mention anything about a round earth Why didn't the Buddha, who knew there were 31 realms of existence, not talk about the roundness of the earth and planets?
The basic project of Buddhism is solving the problem of suffering (or sometimes some other variation of the fundamental problem), usually through a realization about who we really are.

In addition to that, the Buddha didn't bother to challenge many of the other ideas of his day regarding the realms, or karma. (He did take on caste, the economic system, to some degree the inequalities of men and women) He didn't challenge the world's thoughts on a lot of other issues, like medicine, astronomy, geography and so on.

The sutras were written 100s of years later, and accumulated all sorts of unrelated material. By 700 AD, when Vajrayana was well established, the Buddhist canon included books on medicine, astrology and more.

There are many varieties of Buddhism, the secular version dispenses with the cosmologies as instructive myths and the core project of Buddhism remains.

On the other hand, traditional Buddhism still holds the realms to be literally true, necessary for the Buddhist project and proponents like to call doubters "scientist", "materialist" or dismissive of "faith".

If the basic project is to stop the cycle of rebirth and enter a sort of heaven (nirvana), then the realms are essential to Buddhism, without them the basic goal becomes incoherent. If the basic project to end suffering, that is a goal that can imaginably be achieved in this lifetime and it's validity is unaffected by what may happen after we die.