Generally, it's made illegal for environmental reasons, usually to protect the beach against erosion. It depends on who owns the beach. National Parks and State Parks oftentimes have laws on collecting rocks, shells, etc. so that all the public can enjoy it equally.