I use Nexus 7 2012 wifi version. I rooted the device and installed TWRP recovery on it when it was on 4.4.4. Now the lollipop update of 5.0.2 is available to install, whenever I download the update and click install button the tablet boots in recovery mode and gives failed message. How do I get rid of this and install lollipop update successfully?
You can either upgrade to L via TWRP itself (some reported having trouble with TWRP 2.8 and suggested trying 2.7) or revert from TWRP back to stock recovery if you want to go the OTA way (I guess that's what you're trying to do, you're not clear on that in your question).
Also instead of TWRP you can try ClockworkMod recovery.
I use the Nexus Root Toolkit for Windows by wugfresh, it will allow you to unroot and revert to stock with a button click. It also includes full instructions on any setup you need to do prior.
You can find it here: http://www.wugfresh.com/nrt/.
It will also allow you to choose TWRP or ClockworkMod if you wish and can help you install new ROMs too.