Can I enable the COD option for the local pickup and hide all other methods when it happens?

Yes, you can use the Conditional Payments plugin by Dotstore to achieve this. In the mentioned case, you must apply a Condition specific to the shipping class/method and set its value as local pickup. Next, in the Actions section, select Enable Payment Methods and set its value as Cash on Delivery. For caution (let’s say, a payment method is applied through another rule), you can create another Action and Disable Payment Methods (select all other methods).