Hitchcock always gave himself a brief cameo in each of his films: a non-speaking role where he'd basically appear once and never be seen again. It's a little running joke between Hitchcock and his devoted audience, a kind of Where’s Waldo? game he plays in each movie. In Rear Window, he's the man winding a mantel clock in the songwriter's apartment; we see him as Jeff's gaze moves across the windows of the apartments across the courtyard. Hitch winds the clock and turns his face toward the camera.
These cameos were small auteurial flourishes, sneaky signature images that let you know that this is a Hitchcock film. Whenever we see him, we're reminded that there's a director behind the scenes who's creating the story we're watching; it takes us outside the reality of the story for a moment. (Source) What's different about the Rear Window cameo is that he doesn't just appear onscreen suddenly and randomly. We see him because Jeff and the audience have been prying. Yep—so he's part of the voyeuristic action.
In a playful bit of self-analysis, Hitchcock wrote in The New York Times that his motives for inserting himself into his films were "devious, or, if you prefer a more devious word, sinister. I have wormed my way into my own pictures as a spy. A director should see how the other half lives." (Source)
So in Rear Window, we're spying on the spy. It's all so meta.