Is this derivative done correctly? I've did not find the solution in the matrix cookbook, but followed the similar examples:
$$\frac{\delta Y^TY}{\delta Y} = ?$$
$$X=Y^TY$$
$$\delta X=(\delta Y^T)Y + Y^T(\delta Y)$$
$$\mathrm{vec}(\delta X)=\mathrm{vec}(\delta Y^TY) + \mathrm{vec}(Y^T\delta Y)$$
$$\mathrm{vec}(\delta X)=(I\otimes Y)\,\mathrm{vec}(\delta Y^T) + (I \otimes Y^T)\,\mathrm{vec}(\delta Y)$$
$$\frac{\delta X}{\delta Y} = 2(I \otimes Y^T)$$
What you have computed is really $\frac{\delta \operatorname{vec}(Y^TY)}{\delta \operatorname{vec}(Y)}$; I will assume this is what you're really after. I will also assume that you are using the column-major vectorization operator. To correct your mistake, we have the following: $$ \begin{align} \delta\operatorname{vec}(Y^TY) &=\operatorname{vec}(\delta Y^TY) + \operatorname{vec}(Y^T\delta Y) \\ &= (Y^T \otimes I)\operatorname{vec}(\delta Y^T) + (I \otimes Y^T)\operatorname{vec}(\delta Y) \\ &= (Y^T \otimes I)K\operatorname{vec}(\delta Y) + (I \otimes Y^T )\operatorname{vec}(\delta Y) \\ &= [(Y^T \otimes I)K + (I \otimes Y^T)]\operatorname{vec}(\delta Y), \end{align} $$ where $K$ is the commutation matrix of the correct size. With that, we find that $$ \frac{\delta \operatorname{vec}(Y^TY)}{\delta \operatorname{vec}(Y)}= (Y^T \otimes I)K + (I \otimes Y^T). $$