We cannot give the response of "because the Torah says so." Nowhere in the Torah does it give a commandment, explicit or otherwise, to visit the sick. Even so, Jewish tradition cites this week's Torah portion as the basis for this mitzvah:
וירא אליו הי, באלני ממרא. והוא ישב פתח האהל כחם היום
And G-d appeared unto humbly the terebinths of Mamre, as he sat in the tent door in the heat that day. -Genesis 18:1
If you don't see how this verse connects to visiting the sick, you're not alone. By itself, it doesn't make sense, but if you look at Genesis 17, it starts to come together. Right before this verse, Abraham underwent the covenantal process of circumcision to show his faith in G-d. If undergoing such a surgical procedure at age 99 isn't showing faith in G-d, I can think of very few things that would top that. Setting that aside for a moment, the Talmud (Bava Metzia 86b) teaches that G-d visits Abraham three days later, which is what is taking place in Genesis 18:1. We have explained the "what" of the biblical verse, but have yet to touch upon the reason why.
The Talmudic sages (Sotah 14a) understood it through the lens of the biblical verse of "You shall follow after the L-rd your G-d (Deuteronomy 13:5)." The rabbis went into further questioning because how can one follow G-d if G-d metaphorically is "a consuming fire" (Deuteronomy 4:24)? The Talmudic passage in Sotah 14a concluded by saying that we are meant to emulate G-d in His ways, and then cited Genesis 18:1 by saying that because G-d appeared to Abraham, who was ill after the surgery, so should we emulate G-d and visit the sick.
The term for "visiting the sick" in Hebrew is ביקור חולים. What is interesting is the root בקר has multiple meanings, and has implications for the Jewish law (see here, here, here, here, and here for more details on this mitzvah). Yes, it is true that the root בקר means "visit," but it also means "criticize" or "examine" (see Leviticus 27:33). This would explain why examining what the sick person needs and providing for said needs is the first of the three primary halachic requirements of a ביקור חולים visit. The root בקר is also found in the word בוקר, which means "morning." We are meant to provide the ailing individual with a more sunny disposition so they can have a brighter tomorrow, which is why cheering up the individual is the second prerequisite. The Talmud also says that a ביקור חולים visit relieves a sixtieth of one's suffering (Nedarim 39b; Leviticus Rabba 34). The final prerequisite of a ביקור חולים visit under Jewish law is to pray for the individual (Talmud, Berachot 12b).
We are not meant just to physically be present in the room of the sick individual because ביקור חולים is more than a superficial "get well" visit. We are supposed to help them out in whatever way we can, which could help explain why in Mishne Torah (Laws of Mourning, 14:1), Maimonides viewed ביקור חולים as an extension of the commandment of "love your neighbor as yourself." A Jewish existence goes well beyond "what's in it for me?" It's about being able to console others when they are down on their luck. ביקור חולים is about emulating G-d and helping those who are truly in need, regardless of whether they are Jewish or not (Talmud, Gittin 61a; Shulchan Aruch, Yoreh De'ah, 335:1). With specific regards to ביקור חולים, it is important enough of a mitzvah where the Talmud (Nedarim 40a) both illustrates the positive difference a ביקור חולים visit makes, and subsequently compares a lack of ביקור חולים to spilling blood. Visiting the sick is one of the few mitzvahs that rewards you both in this world and the next (Talmud, Shabbat 127a).
By G-d showing an example of loving-kindness (חסד; chesed), Abraham in turn emulated G-d by showing three wayfarers hospitality, even in his less-than-ideal condition. This act of חסד illustrates why Abraham is the archetype of loving-kindness in Judaism. This sort of compassion is so essential to the Jewish psyche that not acting with חסד was so important that the Talmud (Beitzah 32b) stated that someone who is not compassionate is not a descendant of Abraham. Let's take this as an opportunity to emulate Abraham's loving-kindness by emulating G-d's loving-kindness, and may it be a blessing for us all.