Hi @sham2348
You can achieve a similar kind of functionality by manipulating the component edit bar. though you can't lock and unlock component however you can remove edit option from component edit toolbar on the checkbox. you can use ComponentContext and Toolbar API to remove edit option from the component edit toolbar.
you have to perform below steps.
1. Add a node cq:editConfig(jcr:primaryType - cq:EditConfig) and all actions. ComponentContext takes your component's local cq:editConfig node.


2. In PostConstruct method get pageProperties and required property. Get Toolbar using ComponentContext and remove edit (or any other) other from toolbar.
boolean hideComp=currentPage.getProperties().get("hideComponent",false);
if(hideComp) {
ComponentContext componentContext = WCMUtils.getComponentContext(slingRequest);
Toolbar componentToolbar = componentContext.getEditContext().getEditConfig().getToolbar();
componentToolbar.remove(EditAction.EDIT);
}