Shakespeare liked to have a variety of characters in his plays. In Macbeth he has one very strong female role in Lady Macbeth, but there are no other good female parts. The three witches are putatively female but supernatural creatures and not real women. Banquo says to them, in one of the rare touches of humor in this grim play:
You should be women,
And yet your beards forbid me to interpret
That you are so.
Shakespeare may have invented a scene for Lady Macduff to try to give his play a little more balance or variety. The audience has to be able to tell characters apart as they come and go on the stage, and this is a major reason that plays typically feature young and old, male and female, and contrasting types. The scene in which Lady Macduff appears is not really necessary, since Macduff is informed that his castle was stormed and his whole family slaughtered.
Shakespeare must have had permanent members of his troupe who specialized in female roles and may have wanted to give one of them something to do. Shakespeare was not only a writer but an actor, a director, a producer, and a co-owner of the theater. The same youth who played Lady Macduff may have changed clothes and appeared as the Messenger who reports to Macbeth in Act 5:
As I did stand my watch upon the hill,
I looked toward Birnam, and anon methought
The wood began to move.
In many of Shakespeare's other plays it is obvious that he liked plots that would include a variety of characters, especially including females. In King Lear he has three strong roles for Goneril, Regan, and Cordelia. In Othello he has three good parts for Desdemona, Emilia, and Bianca. In Hamlet he has good roles for Gertrude and Ophelia. Even in Julius Caesar he includes roles from Calpurnia and Portia in order to keep his play from seeming like nothing but a lot of middle-aged men strutting around in togas and hard to tell one from the other. In As You Like It, Shakespeare has good roles for Rosalind, Celia, Phebe and Audrey.
This is called "orchestration." In a modern play like A Streetcar Named Desire, you can see how the author developed a plot that would offer good parts for a variety of characters--Stanley and Stella Kowalski, Blanche du Bois, and Harold Mitchell.
In Macbeth, however, although he had one powerful female role, the play was otherwise overfreighted with military men. Perhaps too much importance has been attributed to Lady Macduff. She may exist in the play mainly to add just another female role and provide a little visual and even audio variation. There is also a brief role for the Gentlewoman in Act 5, Scene 1. This "woman" may be the lad who played Lady Macduff earlier, now dressed in a different garb.