Gabe Kaplan was a remedial High School student in Brooklyn. He fashioned his sitcom on the concept of a student from his background, returning as a teacher to teach the next generation of remedial students.
So, to answer the question, Kotter was supposedly a founding member of the Sweathogs, and he was returning to the high school he graduated from to ...
Well, Mr Bones and Ms Daunted's are fine meta-answers, if that's what you were looking for. Pretty sure you wanted the in-universe explanation.
He had no choice in the matter. A bad job market
From the beginning of S01E01:
— You're stalling.
— I'm not stalling. I'm not goin'.
— Ugh. Again? Honey, just be happy that ...