Because the cash the price move added was smaller than the cash the trade cost.
What traders ask is why the take-profit was hit on a long and the trade still closed as a loss. The target is a price. Closed PnL is that price move, minus entry and exit costs, minus funding if you held across a funding time, and minus any gap between the target and the fill. A target a few dollars from entry on a large position can be smaller than those costs. The same confusion shows up right after an open, for a different reason: the spread and the opening cost. That case is why a new position shows a loss.