The function $g_z(Y)$ is defined as $[k] \to \{0,1\}$ where $[k]$ is the set of positive integers till $k$. That is, given a triplet $(z_1,z_2, z_3)$, $Y$ can take any value from $1$ to $k$. If $Y$ happen to be any of $z_1, z_2, z_3$, $g_z(Y) = 0$ due to the definition of $f$ and $g_z$. Now even for different $z$, $g_z$ may be the same. Otherwise, the answer would have been how many ways we can form a triplet $z$ - which gives $k^3$ and for each $z$ we get a function $g_z$.
For all unique combinations of $z_1, z_2, z_3$ are unique, we are guaranteed that we get a distinct function $g_z$. This is clear from the definition of $g_z$. For example, suppose $k=4$. The triplets are
$(1,2,3)$
$(1,2,4)$
$(1,3,4)$
$(2,3,4)$
For the triplet $(1,2,3)$, $Y$ can be made in $4$ ways as $(1,2,3,1), (1,2,3,2), (1,2,3,3)$ and $(1,2,3,4)$. Now, as per definition of $g_z$, we get $g_{(1,2,3)} = \{\{1 \to 0\},\{ 2 \to 0\},\{ 3 \to 0\},\{ 4 \to 1\}\}$.
Similarly, for the next three triplets, $g_z$ are different as in second only $3$ maps to $1$, in third one only $2$ maps to $1$ and in fourth one only $1$ maps to $1$.
So, in general, for any given $k$, we have ${}^kC_3$ ways of forming distinct triplets and each of them guarantees a unique function $g_z$ where exactly $k-3$ elements map to $1$ and $3$ elements map to $0$. Now, if any of the elements in the triplet are same, then the function becomes $\{\{1 \to 0\}, \{2 \to 0 \}, \dots, \{k \to 0\}\}$, (all $k$ elements mapping to $0$) and this remains the same for any triplet. So, total number of possible functions are
$${}^kC_3 + 1$$
Correct Answer: $D$