Sometimes, the same element may exhibit one valency in one compound and another valency in other compound. This property is called as variable valency.
Some elements show variable valency because of the different electronic configurations.
An atom of an element can sometimes lose more electrons than are present in its valence shell i.e. loss from the penultimate shell and hence exhibit more than 1 or variable valency.
The reason behind Why they lose this extra electron is purely a matter of
the specific element,
what electron shell they are losing/gaining electrons in,
and their relative energies to the previous/ next electron shell.
Also their ability to share electrons between these shells
This will be much more clear once you enter higher standards.