I made a version of this gratin the other night, but as a one-pot meal, including courgettes and dried beans as well.
Instead of cooking the courgettes (I had three small ones) separately, I thought: why not simply tip them into the tomato sauce and let them simmer for a few minutes? Then I could add the beans (I used alubia beans, from a jar), warm them too, and pour the whole mixture into a gratin dish. At the moment when I was adding the sliced courgettes, I saw the potential problem: vegetables do not soften in an acid environment. (Do not ever try to cook potatoes in tomato sauce -- unless they are cooked already, in which case they should retain their shape.) But I got away with it. The courgettes were slightly crunchy, but not unpleasantly so.
I topped this mixture of tomato sauce, courgettes and beans with slices of aubergine, and poured my sauce on top of that.