B Neutron, White Dwarfs and Degeneracy Pressure

I have been trying to get some physics behind the cause of the degeneracy pressure but have some confusion with the stuff I have found. Apparently the cause of degeneracy pressure can be explained through the uncertainty principle. If you trap electrons in a smaller and smaller space the momentum becomes very uncertain and approaches the speed of light, hence causing an outward pressure. How does this explanation fit in with conservation of energy. It seems like trapping an electron suddenly gives it a very high velocity which seems to come form nowhere?

If I'm not mistaken, I believe the energy comes from whatever you use to trap it in the first place. In the case of a neutron star or white dwarf, the energy would come from the particle's gravitational potential energy it had prior to dropping to the degenerate state.