This paper reports direct numerical simulations of the flow past rigid and flexible flapping wings under hovering flight conditions. Both passive and active deformations are considered. It is shown that passive deformation can help increase aerodynamic performance through significant wing bending. Bending occurs at the frequency of the prescribed flapping motion and is, in this case, characterized by moderate amplitude and phase lag with respect to the prescribed flapping motion. Bending is then actively prescribed (rather than being a result of passive deformation) with varying phase lag. This allows to decouple the role of bending amplitude and phase lag on aerodynamic performance of the flapping wing. It is shown that both lift and efficiency can be significantly enhanced for phase lags around 3π/2 but this enhancement reduces with increasing pitch angle. The influence of morphing on aerodynamic performance can be explained by the concomitant role of quasi-steady and unsteady effects. These results hence demonstrate that morphing can be beneficial to the aerodynamics of flapping wings. Furthermore, they can help define structural properties that promote aerodynamic performance of flapping wings through passive deformations (with relevant amplitude and phase).