How can I fix the situation, when the label contour lines displays (on top of all layers) on top of this layer?
There is an option where you use a feature as an obstacle to discourage labeling other features if they are overlapping each other. But as far as I know, it just shift the labels of one layer if they are overlapped by another layer. For example in your case you want to prevent contour lines to be labeled when they are covered by "New scratch layer". So you can label the contour line as usual, and use the "New scratch layer" as an obstacle by going to
layer properties -> Labels -> and from the drop down menu select 'Discourage other labels from covering features in this layer', as you can see below
I am not sure if it will be successful in your case or not, but you can give it a try.