Being dead never stopped Posthumus's family: these trusty ghosts show up to save the day when Posthumus is locked away and all hope seems lost. But these are much more than your average ghosts: they also give us a fancy-schmancy deus ex machina at the end of the play. What is that, you ask?
Well, in literature, we're talking about some outside force dropping into a play, movie, or novel to neatly tie things up, resolve the conflict, and pretty much save the day. Here, we've got a bunch of ghosts showing up to give us a neat conclusion.
We've heard of more poetic or realistic endings for sure. But you can't fault Shakespeare for lack of imagination.
Now, this scene could be Shakespeare's way of saying, "Hey, check out this new tech that lets us create ghosts before your very eyes!" We're not gonna rule it out. But the ghosts do show us that Posthumus is still loved and cared for by his family, and that tells us that he's a good guy at heart, even if no around him can see it. So even if these characters are there for the SFX, they do serve a narrative purpose.