Why does taking profit cause the K-line to move in the opposite direction?

Because a take profit order = market order (passive execution, not price picky).

The essence of taking profit is:

Long position take profit → You need to "sell" to realize the profit

Short position take profit → You need to "buy back" to realize the profit

So taking profit is always a trade in the opposite direction.