How do local minima occur in the equation of loss function?
The equation you used for gradient descent isn't general; it's specific for linear regression.  In linear regression, there is indeed only a single global minimum and no local minima; but for more complex models, the loss function is more complex, and local minima are possible.