As for a 401K or similar, it's taxed as income. When you eventually make withdrawals from a traditional defined contribution plan, you'll have to pay regular income taxes on the money you withdraw - whether the money came from your contributions, dividends or capital gains.
So you see, there's a difference in where you are holding your shares, should there be a significant profit.