Let's say the 5th percentile of $X$ is $l_x$ and the 95th percentile is $u_x$, and similarly for $Y$.
You now want to construct a linear transformation $Z=aX+b$ such that $l_z = l_y$ and $u_z=u_y$.
Note that $\frac{X-l_x}{u_x-l_x}$ has the required percentiles at 0 and 1.
Hence $Z=l_y+(u_y-l_y)\frac{X-l_x}{u_x-l_x}$ should match those percentiles with $Y$.
Here's an example in R:
x=rnorm(100)
y=rgamma(100,3,.2)
quantile(x,c(.05,.95))
5% 95%
-1.685679 1.517378
quantile(y,c(.05,.95))
5% 95%
4.724867 29.434846
lx=quantile(x,.05)
ux=quantile(x,.95)
ly=quantile(y,.05)
uy=quantile(y,.95)
z=ly+(uy-ly)*(x-lx)/(ux-lx)
quantile(z,c(.05,.95))
5% 95%
4.724867 29.434846