Case1)
When input voltage at non inverting terminal exceeds Capacitor voltage Vc , diode conducts and Capacitor starts to charge till the peak of input
Case2)
When input falls below Capacitor voltage the output capacitor voltage is held at previous input maximum value thus the input peaks are detected