« كَذَٰلِكَ لِـ… »: "thus it was, so that …"
Hypothesis examined: the construction « كَذَٰلِكَ + لِـ + imperfect » would be a fixed formula, always rendered "thus it was, so that …", the final clause stating the purpose of the preceding divine act.
The survey finds only two occurrences: « كَذَٰلِكَ لِنَصْرِفَ عَنْهُ ٱلسُّوٓءَ وَٱلْفَحْشَآءَ », "thus it was, so that We might turn away from him evil and indecency" (12:24), and « كَذَٰلِكَ لِنُثَبِّتَ بِهِۦ فُؤَادَكَ », "Thus, so that We may steady your Conscience through it" (25:32). A nearby passage (12:21, « وَلِنُعَلِّمَهُۥ ») does not have the same structure.
In the two occurrences, كَذَٰلِكَ does not refer to the same thing: in 12:24, to what has just happened to Youssof; in 25:32, to the way the Recitation came down, in fragments, in answer to an objection. The translation follows these contexts and cannot reduce them to a single formula.
As for the purposive value of لِـ ("so that"), it belongs to ordinary Arabic grammar and calls for no rule specific to the corpus.
In the text
كَذَٰلِكَ لِنَصْرِفَ عَنْهُ ٱلسُّوٓءَ وَٱلْفَحْشَآءَكَذَٰلِكَ لِنُثَبِّتَ بِهِۦ فُؤَادَكَ