Varnish will likely help but it won't completely negate issues with warping and twisting. There are many other things you can do to help:
You are correct in that the key to stopping wood from warping is stopping moisture from leaving or entering the wood too quickly - wood shrinks around 1% in its width for every 3% change in moisture content (IIRC) and moisture leaves through the end-grain around ten times faster than it does from the sides of a board. Drying (or increasing in moisture content) unevenly will cause one part of the wood to shrink faster than another which causes warping. Therefore, one of the largest differences you can make to the stability of wood (short of something like chemical modification of the wood e.g. acetylation - not practical in a home setup) is to seal the end-grain - varnish or paint is not enough - you will get the best results from a purpose-made end-grain sealer which is usually applied as a separate operation before finishing with a paint or varnish. Again this seal will not completely stop moisture transit (there is some very tiny amount of evaporation even through a sealed glass container, after all) but it will do a great deal to slow it and this is what we want - nice gradual adjustment - which helps it to be more uniform across the piece also.
Generally, be careful about how you machine the wood. The surfaces of a piece will always be a bit drier than the inside, unless the wood has been in a stable environment of temperature and humidity for a very long time. If you are to plane or cut the wood down in thickness or width then you should try to take an even amount off of each side, otherwise you can cause uneven drying of what were the inner parts of the timber (which have now become the surface), which may cause cupping, twisting etc.
Similarly if you cut grooves into a piece it may lead to cupping (the groove will typically want to close up as the new surfaces dry and shrink) - I don't know that there's too much you can do about this but if you machine a groove, knock a few blocks the same size as the groove in, every few inches, and allow the wood to adjust in moisture again, with the blocks in place, slowly, before removing the blocks and continuing.
If you're able to allow the wood to acclimatise to its end-use environment, slowly, before processing, and then you're able to keep that environment at a stable temperature and humidity when the end product is in use, this will help with stability. Just by virtue of being used internally, rather than externally and exposed to the elements, the wood will be more stable (assuming that your interior environment is at least somewhat controlled in temperature and humidity).
Another thing you can do (but is dependent on your usage) is to laminate many timbers together with glue - again this will typically increase stability, through the averaging out of defects and twisting/warping forces, but will not always completely solve the issue.
To make it even more complicated, the type of cut (as in, how your board was cut from a log) will alter its stability characteristics, as will other things like how the grain is (straight, wavy, interlocked, etc.) so it can be a real minefield.
So in summary it's really a combination of:
- How the timber was cut from the log.
- General characteristics of the grain etc. of the wood.
- How the timber was dried from the mill (how quickly, to what moisture content etc.).
- How it has been machined after drying.
- How it has been sealed, particularly the end-grain.
- Service conditions.
Typically, a stain or other finish will not cause much in the way of warping - so long as you apply in a thin coat (as opposed to say, dipping and soaking the timber!) and have sufficient warmth and airflow, it will (substantially, if not completely) dry within a few hours and the wood will not uptake a significant amount of moisture from it in this time. Don't be tempted to use a high heat to dry your stain or varnish more quickly - this can cause more problems than it solves.