Inspired by the work of Chen-Zhang [5], we derive an evolution formula for the Wang-Yau quasi-local energy in reference to a static space, introduced by Chen-Wang-Wang-Yau [4]. If the reference static space represents a mass minimizing, static extension of the initial surface Σ, we observe that the derivative of the Wang-Yau quasi-local energy is equal to the derivative of the Bartnik quasi-local mass at Σ.Combining the evolution formula for the quasi-local energy with a localized Penrose inequality proved in [10], we prove a rigidity theorem for compact 3-manifolds with nonnegative scalar curvature, with boundary. This rigidity theorem in turn gives a characterization of the equality case of the localized Penrose inequality in 3-dimension.