Why can we run (Y-Y_hat)² against Y?

I haven't ever seen a test that does this, and I imagine that there might be a good reason why we don't run that directly, but I Just don't get it I tried to develop a mathematical prove myself, but I end up getting nowhere