The nut stops the valve bending when you are pumping it up.
I accidentally bought one of those long-stem valves without any external thread, for deep section rims. When I tried to pump , it would bend all over.
The cap comes in useful if you ride through a muddy puddle.