There can be a lot of these (others have already hit some of these): Changes in temperature and humidity.
As the wood moves, so does the tension on the neck and consequently the strings.
Nut sticking.
If you have a rough nut then sometimes strings can get stuck, causing them to be out of tune.
One way to fix this is to down tune the string half a step, then carefully tune it back up moving slowly.
Ultimately you want to get the root problem for this one fixed though.
General string post slippage.
Depending on how you attach your strings to the posts, they could be slipping there as you tune them up.
In extreme cases they could slip off the posts.
Research a good technique for attaching string securely to counter this.
New string post slippage
This one's related to the other one.
The strings aren't actually stretching in this case, it's usually just settling in on the string posts and the bridge.
Make sure you stretch them out gently and retune after installing new strings.
Tuning machine quality Poorly manufactured tuning machines can cause string slippage as the gear assemblies move.
music.stackexchange.com/users/13/Jduv
The strings stretch over time.
They stretch less and less as time goes on; you'll notice that the older strings are, the less they need to be tuned.
Loosening of the tuning pegs, and that sort of thing.
This can be caused by the tension on the strings, but usually it's due to minor bumps of the guitar and vibration.
Temperature changes and humidity.
Both affect the size (and warp) of various parts of the guitar, which changes the tension of the strings.
Warping (normally very minor).
Wooden parts of the guitar especially bend over time, again changing the tension on the strings.
music.stackexchange.com/users/None/
I think Mathew has hit most of the relevant points, but to add one more thing: Guitar Quality.
Cheap tuning pegs will cause a guitar to go out of tune constantly.
The better the pegs, the less it will go out of tune.
music.stackexchange.com/users/71/yossarian
I believe it's because the constant tension and temperature changes in the strings slowly unwinds the tuning keys.
music.stackexchange.com/users/None/
The strings may not have been stretched properly when they were put on.
Tremolos are also infamous for wreaking havoc with your tuning.
music.stackexchange.com/users/None/
This might be an obvious question, but it would be good to know what factors cause guitars to go out of tune.
Why does my guitar go out of tune after I play it a while?
music.stackexchange.com
<guitar><tuning>
music.stackexchange.com/questions/1348
music.stackexchange.com/users/363/gak
S0: There can be a lot of these (others have already hit some of these):  Changes in temperature and humidity.  As the wood moves, so does the tension on the neck and consequently the strings.  Warping (normally very minor) has an effect.  Moreover, the strings stretch over time. Cheap tuning pegs will cause a guitar to go out of tune. Tremolos also have a negative effect. Temperature and humidity changes affect guitar tuning. As the wood moves, the guitar goes out of tune. Other factors include: Nut sticking, string post slippage, stretching strings and loose tuning pegs. Low quality components on guitars may cause tuning issues. Guitars with tremolo units are often harder to keep in tune.
Temperature and humidity changes affect guitar tuning. As the wood moves, the guitar goes out of tune. Nut sticking. String post slippage. Stretching strings. Loose tuning pegs. The quality of the guitar may have an impact. Cheap components may be less stable. Guitars with tremolo units are more difficult to keep in tune.