If it's a short-term gain (have held for 12 months or less) yes, you pay as if it's ordinary income at your marginal rate.
If it's long term, you pay 0% cap gains if you're int he 10% or 15% marginal tax brackets. Above that, it's taxed at 15%.
In your second scenario of having $5k of gains and withdrawing $5k, no it's not a straight tax on $5k. It's a bit more complicated, but you'd be withdrawing $5k of shares. So some of that $5k would be principal (because of investing at various times, it's not this easy, but let's keep it simple for this example). Let's say 80% of your $25k total is principal ($20k in contributions). That means 20% of every dollar of the $25k is cap gains. So you'd pay tax on 20% of $5k or $1k. Of that $1k of capital gains, you'd likely pay 15% (unless you bring your taxable income down to the 15% or 10% marginal brackets), or $150. Not always as cut and draw, but you'd pay $150 in capital gains tax on the $5k withdrawl in a couple years (for simplicity, I ignored dividends, although VTSAX does pay out a small dividend).