I've seen two theories floated:
1. Vitamin D as a side effect of sun exposure is not itself the important indicator. Instead, some other biological response increases immune response simultaneously. Hence, D supplementation is itself copying the wrong response.
2. Vitamin D deficiency is caused by illness, hence it actually doesn't affect mortality and the relationship is not casual.