From Wiktionary, the free dictionary
när (“when”) + fan (“the Devil”) + blir (“becomes”) + gammal (“old”) + blir (“becomes”) + han (“he”) + religiös (“religious”), "When the Devil grows old, he becomes religious."
när fan blir gammal blir han religiös
- (idiomatic) Said when someone changes for the better, especially in a dramatic and unexpected way.
- (idiomatic) More literally: People often become more religious as they get closer to death