Kinetic Energy = 1/2 x Mass x Velocity^2
Simplified Kinetic Energy is proportional to the Product of Mass and the Square of the Velocity. So if you have a faster firing gun, the reason it hurts more when you use the same ammo is because there is more kinetic energy, just like you said.
When you fire an airsoft gun, the energy stored when the spring is compressed, in converted into energy carried by the BB. The spring will always transfer the same amount of energy to a BB, so according to the equation above an increase of mass result in a reduction of velocity. Conversely a reduction of mass for an equal amount of energy will result in an increase in velocity. The overall energy of the BB is always the same.
There are two things that affect how much the BB will hurt. First is the amount of energy the BB carries, and the second is impulse. Impulse simply is the amount of force applied over time. A high impulse (lots of energy over less time) tends to "hurt" more, while a low impulse (less energy over lots of time) "hurts" less. To visualize this, immagine a rubber ball, and a steel ball, both the same mass. A rubber ball imparts a lower impulse (less force per unit time) and a steel ball imparts higher impulse (more force per unit time) which is why you'd rather be hit by a rubber ball then a steel ball.
The difference in impulse between different BB weights is negligible if not non-existant since they are made of the same material more or less. Hence the amount a BB will hurt is only based on how much energy the BB is carrying WHEN IT HITS YOU.
This is where BB weights matter. A heavier (or technically speaking a more massive) BB has greater inertia. A lighter projectile will have less intertia and the force of friction/wind will affect it much more. A heavier projetile will have more intertia, and will not be as affected.
Therefore at point blank, both a 0.2g and 0.3g BB should "hurt" just the same. However at a longer distance, a 0.3g BB will maintain its velocity, and hence will hurt more.
I hope this helps you understand why it would hurt more or less
EDIT: Also, the reason why lighter BBs may hurt less esp in CQB conditions is because they have less inertia. Hence they would be decelerated by clothing more then a heavier BB which would have more inertia. There are other factors (gas behavior under compression, pressure and force, etc etc etc...) but the ones I have mentioned should be the major ones.