The difference. With A=x+h and B=x:
f(x+h)−f(x)=cos2(x+h)−cos2x=−sin(2x+h)sinh
The quotient. For h=0,
hf(x+h)−f(x)=−sin(2x+h)⋅hsinh
The limit. As h→0, sin(2x+h)=sin2xcosh+cos2xsinh→sin2x and hsinh→1. So
f′(x)=−sin2x
Check by the product rule. f(x)=cosx⋅cosx, so
f′(x)=(−sinx)cosx+cosx(−sinx)=−2sinxcosx=−sin2x
Both methods agree.