The Sime 4 deletes ghosts after a certain amount of time. When the ghost is deleted, it is removed from the family tree. You will get a notification saying that their spirit is leaving. If you don't want the game to delete the ghost, you have to do certain interactions with their grave, such as mourn or leave sugar skulls. That way, they can stay on your family tree. After a ghost is deleted, it will never show up again.
I think the reason they delete ghosts from the game and the family tree probably has something to do with the memory capacities of the game.
That is unfortunately the only way to keep dead relatives in your family tree, unless you want to use an outside website to keep track of them.
In my opinion, the family trees in the Sims 4 are not very good, and I wish it wasn't such a hassle!