It's a layer bug. I just replicated it.
You have a family instance on the wrong layer, so it can not be z sorted.
Also the use of for each is redundant. You could just have the actions on the blank event. Set variable to y, then z sort.