Is it mandatory to square off option on expiry?

Is it mandatory to buy back(square off) position in nifty option if any nifty ce or pe option is written on day of expiry?

Any other charges or penalty will be levied? if not squared off(intraday position)

What is the margin money required for intraday option writing on expiry day?
Is it 40% of total margin? or the margin money can be settled after 3.30 pm on expiry day

It is not mandatory to close positions written on day of expiry.

Ideally your broker might forcefully close if intraday product is used to enter the trade.

It varies from broker to broker and you can write to your broker on this.