One of the major conceits of D&D’s gods is that their very presence powerfully affects reality around them. They literally cannot go anywhere without warping reality to be more in line with themselves—and that isn’t something that does you any favors with the other gods, even those who are otherwise friendly towards you. Showing up somewhere important, particularly the Material Plane, in person is a good way to get every other gods’ attention, and even your allies aren’t likely to support you. You are literally damaging the plane by your very presence and it’s simply not OK to do that.
There are some exceptions. The Outer Planes are far more resilient, since they are already so strongly aligned, and a god with an invitation and/or paying the proper respect to the places they travel to or through can avoid doing so much damage. And a few gods do roam the planes, even the Material Plane, rather than set up their own divine realms; they can do this because roaming (and not putting down roots and affecting things) is part of who and what they are, and consequently they don’t warp things so much. But when a god goes somewhere forcefully where they aren’t welcome, well...
For reference, gods being in places they shouldn’t be, in person, has been used as an explanation of why the laws of physics—the game’s rules—have changed from edition to edition. That is the level of effect we are discussing here.
So in order to avoid pissing off the other gods, most deities will usually avoid doing things in person. They’ll operate through proxies and champions, or when they really need to do something themselves, through an avatar. In a lot of ways, an avatar is a lot like a very particular conjuration spell: it creates a physical representation of the god, with some of that god’s divine essence invested in it. The god can “pilot” the avatar as an extension of themselves—which is exactly what it is.
But importantly, the avatar only has a fraction of their power. It doesn’t warp reality as strongly—it still does, but not nearly as much. It’s far easier to justify the use of an avatar to the other gods. The damage it does is more localized, and easier to undo.
It also explains why the “god” can be defeated by mere mortals—that wasn’t the real god, you see, just an avatar. Many, many adventures have claimed that the adventurers are fighting a god, only for later canon to ret-con that to an avatar, to allow the god to continue to be used and to explain why the god was so “easy.”
In terms of what happens when an avatar is killed, it does hurt the god. They have invested some of their essence and divine power into the avatar, and that being destroyed hurts them. How much is left largely up to the DM and/or adventure authors, but the destruction of an avatar “shouldn’t” be just ignored. It’s a major event and should be portrayed as having consequences for the god in question.
As for truly killing a god, it can happen (the Astral Plane is known to be littered with the corpses of dead gods), but it’s pretty rare, especially these days (where almost-all gods are well established and entrenched, and exceedingly difficult to approach even for other gods). Usually, it involves a beat-down by another, stronger god. And often times, even that doesn’t stick—if the god in question still has believers, then the god can be restored through their faith alone. So in practice, starving a god of faith is the only real way to get a god to die and stay dead. That generally means diminishing the god, killing or converting their followers, or destroying the god and then subverting its faith to another god so that it can’t go to restoring the original god (Shar has something of a specialty in this).
The other thing known to be quite capable of killing a god is the Lady of Pain. She flayed Aoskar, a god of portals who made the extremely unwise choice of attempting to move to Sigil and claim that the Lady was, in fact, an aspect of him. When one of her dabuses converted to his faith, she took it personally and destroyed him. It’s unclear what would happen if a significant number of people began to believe in Aoskar again, but the Lady has been quite clear that to do such a thing would be exceptionally foolish and in practice he’s more of a punchline than a god now. Considering that there are precisely zero gods interested in disrespecting the Lady (despite the incredible power Sigil might offer) certainly suggests she could do the same to gods much more notable than Aoskar, too.