Which Gintama episode has this scene of child Gintoki looking back upward to the camera in the sunset?
This is actually the front/main cover of the DVD for Gintama Season 04 Vol. 8.
It's not taken from any scene or episode, nor does have any background story.

References:

Gintama Fandom Wiki
Aniplex (Japanese)