Why were my sold holdings bought back on the same day?

Because the sell order was placed under the Intraday product, not Delivery. An Intraday trade has to be closed the same day, so if you don't close it yourself, the system squares it off automatically — buying back the quantity you sold — shortly before the market closes. It doesn't touch the shares in your demat, so your holdings stay intact, and you're left with only the intraday profit or loss (and any charges).

Why didn't selling reduce my holdings?

Selling removes shares from your demat only when the order is placed in Delivery (which needs the full quantity from your holdings). An Intraday sell doesn't debit your holdings — it opens a same-day position that must be closed that day, so it gets auto squared off (bought back) at the close if you don't close it first.

How do I actually sell my holdings?

Place the sell order in Delivery — that debits the shares from your demat and exits the holding. If a sell is already open as Intraday and you meant it as an exit, you can convert it from Intraday to Delivery before the auto square-off, so it delivers from your holdings instead of buying back.