An electron enters because it gets close enough to the positive charge on the nucleus, and is attracted to it. The electron typically comes from another atom (eg, ionic bonding). Energy is released when an electron enters the valence shell as it is entering a lower energy state (if not, the energy barrier for the electron to 'leave' its previous atom would be too great - if you look at MO diagrams the bonding orbital is lower energy than the unbonded electron in the shell for a bond to form), and the difference in energy is emitted as heat or light.