We know that metal has free electrons (negatively charged particles) in its surface. But free electrons cannot escape from the metal surface unless there is a push or pull. If electrons attempt to escape from the surface of the metal, it will acquire a positive charge hence it will attract back the electrons to the surface.
So as mentioned earlier it requires sufficient energy to overcome the attractive pull. A certain amount of energy is required for an electron to pull it out from the surface of the metal. That minimum energy required is known as the work function of the metal.