There are several tremendously good answers to this question, and I hope my personal experience will at least add weight to some of the other answers.
I used to play an lot of Team Fortress Classic. Some weeks I probably played 40 hours.
If you're at all familiar with TFC, you'll know that they had class-based play, and one of the classes was a sniper. You'll also know that probably the most common map (pretty sure it was the default map if you started a server) was 2 Fort. It looked like this:
Each base was a mirror image. Between the bases you have a long bridge over a moat. Beneath the battlements are two doorways with very little lighting. In the middle of the battlements you also have a sort of bunker with poor lighting. In a typical game involving snipers, you would find them hiding in the darkness in the doorways (though less often, as these were fairly high-traffic areas, and the sniper was pretty poor in man-to-man combat), or more usually sneaking out from the top battlements to take a shot.
While the snipers did have one-hit kill abilities, the game was still balanced, due to the following:
- one-hit kill shots required both time and precision. The sniper had to 'charge' their rifle by holding down the trigger button. Then they had to hit the enemy in the head.
- The sniper rifle had a "laser" sight, i.e. a red dot that appeared wherever they were aiming. Skilled snipers would do their best to hide the dot until the last possible moment. If you were on the receiving end, typically you'd only know there was a sniper waiting for you when your vision turned red the moment before you instagibbed.
- When charging the rifle the sniper movement was very slow. This made them fairly easy prey for splash damage weapons.
- If you could move quickly, it was pretty easy to dodge the hit. Or if they shot your friend in the face, you could take them out while they were re-charging their weapon.
- There were multiple avenues of entrance to the base. Sure the main courtyard was wide open, but there was a water tunnel that came up under the bridge. If you wanted to enter the enemy base unseen that was a reasonable option. You could then come up behind the snipers either in the bottom of the battlements or up through the main ramp room, past the spawn point, and out into the battlements. Or you could do an assisted jump up the grate and come out by the spawn point and through to the battlements.
- Pyros had fire weapons, and when lit on fire your vision would be obscured. This made it difficult for snipers to see where they were aiming.
- Medics and scouts were fast, and if they used a concussion grenade to propel themselves they could easily move faster than most snipers could track. Of course you did get the lucky "skeet" shots. Concussion grenades would also disorient the snipers.
- Spies could disguise themselves as the enemy. Even your crosshairs would take on the name of one of your own teammates with that same class.
Snipers had certain strategies that they would employ, but there was always some way that you could deal with them - even without becoming a sniper yourself.
TFC also had a nice way of preventing camping - you typically had multiple respawn points (2fort had 3 spawn rooms, two of which had two entrances. One came out the right side of your own battlements, and the other let you drop down in the middle of your own base. The third was near your flag in the basement. But you could go up the elevator or the spiral to get into the rest of the base) and these spawn points had built-in turrets that were extremely powerful. All you had to do to stop someone camping in front of your spawn point was open the door. You might die once, but the camper would be pretty dead right after that.
I think the most appropriate anti-camping lesson you can take from TFC is one about balance. Each class, each position had some sort of Achilles' heel that required teamwork. The best story that I have about this comes from the map called Well. The Well felt like a much larger map than 2fort - again it was symmetrical, with two large bases facing each other over a large courtyard. At the top of each base there was a catwalk that was only accessible via ladder from the outside of the base, but offered a commanding view of the central field, and some camouflage. Below that was a sniper deck, accessible from within the base, and then the main door. The main feature of the central field was a tunnel across the center of the field that served as a sort of wall. However, in that tunnel was access to the sewers, which (if someone destroyed the grate) allowed you access to the flag room of the opposing team.
The most relevant feature of Well for my story though, is that there were only two spawn rooms. They were across the ramp room from each other, and on exit you had two choices - go into the ramp room and left to go into your flag room (large, with a silo), or up the ramps, across the sniper deck, and up into the attic (which also led into the flag room on the other side). The attic had a singularly interesting feature - a large oblong hole in the floor. If you were an engineer, you could place a sentry gun here. At level 3 it would protect well against all but the most coordinated assault. And with multiple supply packs spawning in the attic, a lone engineer could protect their base... as long as their grate was intact.
In my case, however, it was an enemy engineer who set up his sentry gun in our attic.
At that point, my go-to class was a soldier. Slower, but with more armor and firepower that suited me just fine. The team I was on was getting destroyed by the enemy. They were on a cap(ture) run - as soon as our flag was captured, they already had a man waiting to pick it up when it was returned to our flag room. So I walked out of the spawn room, ready to do some damage, when to my surprise I was turned into ground beef by a sentry gun inside my base. Next spawn I tried sneaking out, only to have my leg blown clean off. I even tried throwing a nail grenade up into the attic on a suicide mission, but if the engineer is hiding behind his gun repairing it that doesn't work. And it didn't.
Next I tried a heavy weapons guy. His minigun and massive amounts of armor make him quite powerful. Unfortunately for me, his slow speed also makes him a sitting duck. Or shredded duck, in my case.
Finally I had the right thought - an engineer with an EMP grenade. An EMP grenade will usually take out a sentry gun, and the more armor and ammo you're carrying the bigger an explosion you make. Enemy engineers make very large explosions. Priming the grenade, I ran out of our spawn room and launched it into the attic. The fireworks were spectacular. I destroyed the sentry gun and the enemy engineer (alas, I died also, but you know - respawn), and then went and put up my own sentry gun. I was able to put a halt to their cap run, and even capture their own flag a few times myself.
It was one of my most memorable TFC games. Under most conditions, an engineer would never have made it to that point of the base and had the time to setup a sentry gun. But the players on the team I joined were a little overwhelmed (out of balance). They just needed the scales to not be tipped quite so far in the favor of the opposition.
Balance is what makes a game fun, and is a great way to prevent camping. If your maps are well balanced, and your weapons are balanced, and your teams are balanced, your game will be fun.
If you want to encourage sniping, but you want to prevent the snipers from just setting up shop and not moving, give them a reason to move.
- Make it dangerous to stay in one place for long, either because the enemy can sneak up behind them, or as others have mentioned, call in an airstrike or mortar or make it possible for them to get hit with a rocket.
- Make it pointless to stay in one place for long: maybe the battle moves back and forth along the map. Either the sniper has to advance because there's nothing for them to do, or they have to retreat because they're going to die.