What does 'gotcha' mean? When would you use it?
Gotcha actually has several meanings. All of them can be derived from the phrase of which this is a phonetic spelling, namely "[I have] got you".
Literally, from the sense of got = "caught, obtained", it means "I've caught you". As in, you were falling, and I caught you, or you were running, and I grabbed you.
It's a short step from the benign type of caught to the red-handed type of caught. Thus, gotcha is often used when you witness someone doing something naughty.
Again, it's a short step from I-caught-you-doing-something-you-oughtn't to Surprise! I tricked you! This sense of gotcha is used when someone falls for a practical joke, for example.
A somewhat-natural progression from the "I tricked you" meaning is gotcha used as a noun: this is a feature of a system (e.g. a programming language) which trips you up or catches you off-guard.
And finally, from the figurative sense of got = "understood", gotcha can be used to mean "Aha, I see now" or "I understand".
Following from Jasper Loy's statement.
It is short for "Got you!", itself having the subject implied "I have got you.".
It regularly means, at least in the UK, "I understand [what you mean]".
A: You turn left, then right, go straight on and it is on your left.
A: They'll never know who did it... <manic laughter>
B: Gotcha! You little tyke!