Are lektion and läxa interchangeable, or does läxa refer to lessons learned during homework?
No. While homework is uncountable in English, läxa is countable as one of the tasks assigned for homework. The translations here are idiomatic, meaning being forced to learn or adapt.
Also, the 1 hr session you might have with a teacher and other students can only be called en lektion, never 'en läxa'. Also a chapter in a book can be Lektion 1, 'Lesson 1', but it'll never have the title "Läxa 1" (that would be 'Homework 1')
And on Duolingo, he succeeded!
Basically this lesson/läxa is if he had done something bad and had to learn a lesson