What is the purpose of the appearance and speech of the messenger in Act 4, Scene 2? Who might have sent this messenger?
In Act 4, Scene 2, the messenger who appears has come to tell Lady Macduff that her life is in danger and that she should escape with her children as soon as possible. This is what he says:
Bless you, fair dame! I am not to you known,
Though in your state of honour I am perfect.
I doubt some danger does approach you nearly:
If you will take a homely man's advice,
Be not found here; hence, with your little ones.
To fright you thus, methinks, I am too savage;
To do worse to you were fell cruelty,
Which is too nigh your person. Heaven preserve you!
I dare abide no longer.
The messenger proclaims that Lady Macduff does not know him, yet he feels obligated to let her know that she must flee at once. He is "homely" which implies that he is an ordinary citizen or someone not of high rank. He is very polite and considerate and is sorry to disturb Lady Macduff, but he feels it's his obligation to warn her of the coming peril.
The fact that he is unidentified suggests that, during tyrannical Macbeth's rule, no one feels safe, so he should better not disclose his identity. What we can infer about the messenger is that he is definitely an opponent of Macbeth's rule, which means that he may be a supporter of Macduff or a soldier who may have found out about Macbeth's evil plan to have Macduff's family executed. The fact that he comes right before murderers show up to kill Lady Macduff and her children means he must have found out about Macbeth's plan very late.
Unfortunately, Lady Macduff does not have enough time to run away.