It would be insensitive in-universe, but in real-world terms, the producers didn't want the viewers to go away depressed, so the conceit of a "happy ending" was used.
In Operation: Annihilate!
, the brother of Kirk dies
and the episodes ends with jokes about vulcan ears...
For a modern viewer, it can be unsettling... I can't imagine a episode of a modern tv show ending with a light note after a close relative of the main protagonist died...