All the boys in Holes have their own nicknames while at Camp Green Lake. Stanley receives his nickname in Chapter 9. While in the "Wreck Room", Stanley accidentally bumps into the camp bully, Derrick, who then tries to instigate a fight with him. In an attempt to deescalate the situation, X-Ray and Armpit chime in and tell Derrick that "You don't want to mess with the Caveman."
It is not clear exactly where they came up with this specific nickname. They certainly wanted something intimidating sounding to get Derrick to back down. The name most likely refers to Stanley's large size, which makes him sometimes seem like what they imagine a caveman to look like. Stanley does not think the name is particularly fitting for him, because he does not feel that he is as tough as the name makes him seem. The nickname is further cemented into Stanley's identity after he finds an ancient fossil of a fish in the next chapter.