Derivative gives us the slope of the function.
When there is a relative or local maximum, to the left of the maximum, the slope is positive as the function increases as we move to the right towards the maximum. After the relative maximum, the function decreases, the slope is negative. So slope is negative to the right of the maximum.
In between the left and right sides of a relative maximum, the slope changes from minus to plus. In between at the maximum, it has to become zero.
As the derivative is nothing but the slope, the derivative is also zero at the relative or local maximum.
Similarly, when there is a relative or local minimum for a function, the function first decreases and then it increases. That means the slope is first negative and then it becomes positive. In between at the local minimum it is zero.
Thus the derivative is zero at the local minimum, as it is the slope of the function.