It’s a movie, so we can’t go 100% with realism. In the real world, it can be very dangerous to pull up to attempt to disengage from a dogfight. This is because you lose speed rapidly as you gain altitude. At best, with full throttle, most combat aircraft will merely maintain airspeed during a steep climb.
The big risk would be giving Maverick an easy kill that he could make quickly enough to remain relatively close to the ground.
Regarding realism, I don’t believe that an F-15 has ever performed Pugachev’s Cobra, and I can’t find any online sources confirming that it has ever been done in an F-15.
Also, the Cobra is not a wise dogfight maneuver because it bleeds off almost all airspeed. Even forcing an overshoot, which is a normally sound tactic, would not make up for the loss of almost all airspeed. Another problem with the Cobra is that at the moment of overshoot, the defender cannot see the attacker, because the defender’s plane will be between the defending pilot and the overshooting attacker. So as a defender, you now have essentially zero airspeed, you’re kinda stuck in a stall position with extremely high AoA, and you have no idea where the enemy is. You have to recover/complete the maneuver over the course of several seconds and then attempt to re-acquire your target and then hopefully have enough airspeed to maneuver for a shot. This is not a sound tactic.
Two maxims of dogfighting are “speed is life” and “lose sight, lose the fight”. We can see in the Top Gun movies that dramatic footage and story are valued over real world dogfighting tactics.