As you know, ionization energy is the energy needed to remove one mole of electrons from one mole of atoms in the gaseous state
#color(blue)("X" + "energy" -> "X"^(+) + "e"^(-))#
Right from the start, you can tell that the harder it is to remove an electron from an atom, the higher the ionization energy will be.
Now, the periodic trends for ionization energy can be describe as follows
- ionization energy increases as you move from left to right across a period
- ionization energy decreases as you go down a group
As you mentioned, if you compare the first ionization energies for oxygen and chlorine using these two trends, you will get conflicting results.
If you follow the way ionization energy increases across period, chlorine would have a higher ionization energy, since it's closer to the noble gases.
On the other hand, if you go by how ionziation energy decreases from top to bottom in a group, oxygen would have higher ionization energy, since it's located in period 2, as compared with period 3 for chlorine.
As it turns out, the trend for groups overpowers the trend for periods. As aresult, oxygen will have a higher ionization energy than chlorine.
This happens because the smaller oxygen atom has its outermost electrons held tighter by the nucleus. By comparison, chlorine's outermost atoms are located further away from the nucleus.
Not only that, but they are screened from the charge of the nucleus better, since they're located on the third energy level.
Oxygen's outermost electrons are screened by
All these factors will make chlorine's outermost electrons a little easier to remove, which implies a smaller ionization energy than that of oxygen.