Briefly, this works very nicely when $Y$ is locally compact, but not otherwise.
Then the function space carries the compact-open topology.

John Isbell gave a survey of the story and literature in  his paper
<i>General Function Spaces, Products and Continuous Lattices</i>,
in Math Proc Cam Phil Soc <b>100</b> (1986) 193--205.

It is an ongoing matter in theoretical computer science.