Why were electrons coming out from a metal when it was kept under a light source?
Light is a form of energy. The free electrons in the metal when get sufficient energy from light, they jump out of the metal
Free electrons are free to move but only within the boundaries of a metal, they are still attracted by not one but many atoms, so they cannot leave the metal surface.
Light is a form of energy. When it falls on an electron it transfers its energy to it. The free electrons in the metal, when they get the required energy to leave, they jump out of the metal.