You pay tax on the gain because you received the money in your account. It doesn't matter what you do with the money after you receive it. It was your choice to reinvest it.
What does a retirement distribution have to do with it? If the gain was in a tax-sheltered retirement account such as an IRA or 401(k) it would not be reported on a 1099 and you would not pay tax on it. In a regular taxable account you can take the money out anytime you like. You do not have to save it for retirement.