Do I need a comma after "when" in the sentence:
He was still a young man in 1843 when he wrote the story.
No, you do not need a comma after "when" in the sentence. This is because when is a subordinatating conjunction that begins an adverb clause. https://owl.english.purdue.edu/engagement/2/1/37/ is a reference for this.