Gotcha actually has several meanings. All of them can be derived from the phrase of which this is a reduced speech form, namely “I (have) got you”.
1. Literally, from the sense of got = caught or obtained. It means “I’ve caught you”, as in you’re running and I grabbed you, I’d say “Gotcha!”
2. The sense of gotcha when someone falls for a practical joke (prank); “I tricked you”.
3. The figurative sense of got = understood. Gotcha means “Aha, I see now” or “I understand“.