Although shaped well to hide in cracks, shore crabs actively leave shelter to seek food.
Shore crabs can hunt and scavenge along the shore above the waterline because they can hold water in their bodies next to the gills, drawing on the oxygen from the stored water for some time. What if it rains? With their exoskeletons and their “above water breathing system,” shore crabs are also quite tolerant of exposure to rain and runoff.
The crabs and other animals under rocks are there because they require the protection: it’s important to replace anything you move to the original position to restore their protection.