You can't separate the variables directly. The way to solve it is to multiply the whole equation by e^x. You'll then notice that since d (e^x)/dx = e^x, the right hand side is just the product-rule expansion of d(e^xy)/dx. So, you have
\frac{d}{dx}(e^x y) = e^{2x}.
Now you can separated the variables. You may wonder why I multiplied by e^x. In general you would multiply by some unknown function \mu(x), which you then chose by demanding that you can write the left hand side as d(\mu y)/dx. This requires setting the coefficient of y (after multiplication by the \mu) equal to d\mu/dx. In this case it gives d\mu/dx = \mu, which gives the exponential.
In general, the factor that you multiply by will be
\mu(x) = \exp\left[\int dx~(\mbox{coefficient of}~y)\right].
Notes: this trick only works for first order linear equations, you may not get a \mu(x) which you can express in terms of elementary functions (but it still gives you a solution), and the arbitrary constant of integration in the above expression doesn't matter (it will cancel out in the end).