Do i have to have the margin if OTM option becomes ITM before expiry?

Suppose if I buy OTM option of any stock which is becoming ITM before expiry do I need to have the margin on the day it becomes ITM or on the day of expiry only?

You’ll need to have margins when the option becomes ITM and margin requirement increases.

The Exchange charges physical delivery margins as a percentage of applicable margins of the underlying stock which is levied from expiry minus 4 days for long ITM options. You can check out this post for more information.

Also if I sold by holding today can buy it back with the amount received from selling holdings with the intention of selling it again?

like if I had 100 shares in my demat account

and I sold 100 shares next day then on same day I buy 80 shares and then again sold those 80 shares. Assumming I don’t have extra margin will this result in margin shortfall or penalty?

You can, would suggest you read this post for better understanding.