This is something very common, that we all have been seeing since as long as we can remember. This question stemmed from my recent re-watching of Django Unchained, where Quentin Tarantino makes a cameo appearnce. I have always been intrigued by this. M Night Shyamalan, Peter Jackson, John Carpenter, Robert Rodriguez, Eli Roth, and many more, have made frequent cameo appearnces in their movies. The trend goes as back as Alferd Hitchcock's movies. I want to know more about this. What are the factros behind this gesture ?
There's no overarching right answer to this. I think there are a few reasons for it:
For starters, it's fun. You've mentioned lots of directors in your question who have done it and it's likely they all got a pretty good kick out of it. Think Hitchcock's many roles or Tarantino in Reservoir Dogs, or Pulp Fiction.
There's also a tradition argument. Stan Lee, for example, has done it for so long now that it's expected and many fans get enjoyment out of spotting him in each of his roles. The same applies to Hitchcock.
After the fun and tradition reasons, it's certainly plausible to suggest because they can. Many directors don't have the fame or recognition for a cameo role to be significant. But if someone like Tarantino, Scorcese or Peter Jackson does it, it's instantly recognisable given their fame. This can be compared to other, less famous, directors who wouldn't be recognised. Therefore, it certainly carries that making cameos gives them airtime and keeps them recognisable in the public eye.
These are just a few of the reasons. I'm sure other arguments could be made, such as the fact it saves money (such as in the case of a longer role, e.g. Tarantino in Django), but it seems to be mostly about a mixture of fun and tradition.