So why does this happen? Well, if it only happens to you occasionally than I wouldn't worry - it happens to every angler from the beginner to the most experienced in the world. However, if you're constantly losing fish while playing them you're probably doing something wrong as common sense would dictate. It could be how you handle your fly line, the angle of your fly rod during the fight, or the amount of pressure you're putting on the fish & line. There's a lot of things you have to do to bring a fish to hand, but that's what makes it challenging.
I once had a fellow who worked part time as a fly fishing guide tell me that the two things most anglers do that causes them to lose a fish off the hook is that they either a.) put too much pressure on the fish; or b.) move around too much while fighting the fish. To me that makes sense.
It's a natural reaction when you set the hook to keep a lot of pressure on the fish, but the trick is to set the hook with some force, but then to let up a little. You have to keep constant pressure on the fish the entire time, but you don't want to stretch the limits of your fine leader. Remember, the heavier the fish, the less pressure you can put on it before your tippet snaps. Of course you can go too far the other way, allowing slack line, for if you do the fish will almost certainly be lost. What you need is a nice, even pressure to wear the fish down as it fights. This might be hard to do while your adrenaline is pumping like crazy, but it's a skill you're going to need to land the most fish.
Sometimes we make the fight with the fish last too long. The idea here is to bring the fish quickly to the net or hand, that way you don't give it any time to escape the hook. Sometimes in an attempt to play out, or tire, the fish an angler can go too far & exhaust the fish. That can lead to it's demise & kill it. Playing a fish too long is unnecessary & unsportsmanlike. Don't ever extend a fight with a fish on purpose because you think that it's fun.
Another reason a fish can jump off the hook is because the angler is too animated & thus really scare the fish into an uncontrollable panic. Trout, especially, can actually harm themselves in such a panic.
It's not that the fish has the comprehension enough to understand exactly what's going on. Rather, they see a large shape along the shoreline or protruding from the water (you) & as long as you remain fairly still they take you to be a large bush or some other object naturally along the stream. However, if during a fight with the fish you should be jumping around, waving arms, churning the water with your legs, & running up & down the stream the fish will have it in its small instinctive mind reason enough to figure that the large, thrashing blob (you) is associated with the hook in it's mouth or the weird pull it keeps feeling toward that crazy blob. That would be a little scary.
So it's best to remain in one place when playing a fish if you can - sometimes, like when salmon fishing, you don't have a choice & you will be following the fish up or down stream. When this happens try to do so as calmly as you can. It will be safer for you, any other anglers, & your gear.
So when you hook a nice fish be physically calm & as stationary as you can & land the fish as quickly as you safely can - ideally before the fish has an idea of what's going on. Do plan out how you will bring any fish to hand before you hook up.
Playing & fighting a fish can be great fun. That said, I still feel that the biggest thrill from the sport comes from the take - the fooling of the fish to take your fake fly as real food. When that happens I know my theories & ideas worked & I want to get on to trying to fool the next fish.