What sort of crabs do you have?
causes could be numerous things from fighting with other crabs, fish or even problems moulting. It is hard to say if it gives them any pain as it is not known to what extent crabs feel pain (though it probably hurt them when it happened) it would not be the same as you or I losing a leg. The legs should grow back when the crab moults though it might start of looking different to the others, each time the crab moults it should get bigger and stronger (sometimes after even 1 moult the legs can be almost the same as the other legs) everynow and then legs won't grow back, though this is rare.
If you need any more info on keeping crabs please ask as they all have different requirements.
Hope this helps