Stage directions perform a variety of different functions. On one hand, a playwright's stage directions allow the actors to know who should enter the stage and from where they should enter or exit the acting area.
Enter Kent, Gloucester, and Edmund
Exeunt GLOUCESTER and EDMUND
Should they enter from the left, from the right, or from some other direction if the play is being done in a theater with a different configuration (e.g., semi-circular; circular). These sorts of stage directions allow the playwright to direct traffic, so to speak, to make sure the actors don't run into one another on stage.
Stage directions also help actors know what should be done with the various stage properties (e.g., sword), what sort of gestures they should make (e.g., pointing, waving), how they should speak (e.g., angrily). Should an actor speak directly to the other actors or should the actor deliver the lines as an aside, as Cordelia does here:
Although the plays of Shakespeare and probably most other playwrights are really meant to be viewed rather than read, for modern students of the plays, stage directions give us a better understanding of what's happening on the stage. If modern readers did not have stage directions, how would we know that a character is supposed to speak angrily, wave their hands, be carrying an object, etc., unless an actor's words revealed these things.
Sometimes a gesture can be deduced from an actor's words, as when King Lear gives Kent a crown ("This coronet part betwixt you"), but many times a reader would not know unless there were a stage direction, as in this remark and gesture by King Lear:
O, vassal! miscreant!
Laying his hand on his sword
If it were not for the stage direction, the reader would not immediately know that Lear was angered to the point of doing violence.