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 General Function Spaces, Products and Continuous Lattices, in Math Proc Cam Phil Soc 100 (1986) 193--205.
It is an ongoing matter in theoretical computer science.