Pin risk happens when a stock closes right at your short strike on expiration. You do not know if you will be assigned until after the market closes. This creates uncertainty.
You sold a 100 call. The stock closes at 100.01 or 99.99. You do not know if the call will be exercised. The buyer has until 5:30 PM ET to decide. You might wake up Monday with a short stock position you did not expect.
After hours movement. The stock can move after the close. If you are assigned and the stock gaps Monday, you have a position you did not plan for. Margin calls. An unexpected short stock position might require more margin than you have. Weekend risk. You cannot exit until Monday. A lot can happen over a weekend.
You sold a 50 put. Stock closes at 50.05. You think you are safe. After hours, bad news drops the stock to 48. The put holder exercises. Monday you own shares at 50 that are now worth 48. You lost 2 dollars per share on a trade you thought expired worthless.
Close before expiration. Do not hold short options into expiration day if they are near the money. Close by Thursday if expiration is Friday. Roll early. If you want to stay in the trade, roll to a later expiration before the final day. Accept assignment. If you are okay owning or shorting the shares, pin risk is not a problem. Just be prepared.
If your short option is within 1% of the stock price on expiration day, close it. The premium left is not worth the risk of surprise assignment.