I’m generalising this to: what is the purpose of the phatic function of language—of which hello and goodbye are canonical examples.
In linguistics, a phatic expression /ˈfætᵻk/ is communication which serves a social function such as small talk and social pleasantries that don’t seek or offer any information of value. For example, greetings such as “hello” and “how are you?” are phatic expressions.
The utterance of a phatic expression is a kind of speech act. According to Malinowski, even such apparently “purposeless” communication as polite small talk, like “how are you?” or “have a nice day,” even though its content may be trivial or irrelevant to the situation, performs the important function of establishing, maintaining, and managing bonds of sociality between participants.
Oh, and btw:
Besides speech, in the digital world, phatic expression can also cover digital interactions. For example, liking someone’s social media post can communicate social approval and as a consequence build rapport.
You say hello, for the same underlying reason you Like (or Upvote).
We use phatic expressions, because we don’t speak just to convey information. We speak to be sociable. In fact, without being sociable to others, we may not get to the point to conveying information to them at all.