If I put some beer in a secondary vessel for medium-term condition (e.g. lagering or dry hopping), do I need to put an airlock on it or can I just close it up with a stopper or put it in a keg and seal it? Presumably the yeast are not really generating any more CO2. (Note: I'm not talking about an actual secondary fermentation with fruit or something, where the yeast will clearly be active.)
You absolutely do not need an airlock for secondary, assuming you wait til fermentation is done. I've sealed a carboy with a stopper many times for a secondary, although these days I usually use foil. If the beer is still outgassing, you will have a bit more dissolved CO2 in it, but not enough to worry about the carboy exploding. A keg also works really well and can be vented by pulling the relief valve if necessary (although it almost never is). The best alternative, IMO, is to just not use a secondary.
The yeast may still be working, and even if they aren't, CO2 may still be coming out of solution from temperature changes or agitation. Glass carboys are not meant to hold pressure, and they fail in a very dramatic and possibly dangerous way. Use an airlock for safety.
A keg designed to hold pressure is a fine alternative. You can even keep it under pressure so when the lagering period is done, your beer is fully carbed and ready to drink.
You used the term "lagering", so if you are truly lagering, the answer is 'it depends'. If your beer is indeed a lager, then your yeast WILL be active....potentially down to freezing temperatures (if your yeast was treated kindly and your temperature lowering regimen was patient). I only make this point since things are moving very slowly at this stage and fermentation will not be obviouls, but it IS happening and pressure will eventually build up. The "it depends" part is regarding off flavors. If you are confident that any hydrogen sulfate produced by the lager yeast has been out-gassed, then it's time to seal the corny keg and allow natural carbonation to develop. Generally late in the lagering (secondary) phase of fermentation, you can rest assured that most of this has already been driven off by more vigorous fermentation.
If you are simply cold conditioning an ale (for whatever reason), then comments posted by others make sense.