It is important to understand the difference between realized and unrealized capital gain/loss. The gain or loss is only realized when the underlying asset is sold. In the case of a capital loss, most or all can be washed out if asset is repurchased at a price lower than the original cost basis.
Selling options, when exercised, moves me into and out of the underlying stock. Therefore the realized capital gain or loss moves up and down.
It all about the revenue received.