A creature's abilities are checked at the time blockers are declared (the declare blockers step). If a creature has flying at that moment — even if it just gained flying from an instant spell cast moments earlier — it may block as though it always had the ability.
Flying (CR 702.9) allows a creature to only be blocked by creatures with flying or reach, but it also grants the creature itself the ability to block creatures with flying. There is no rule requiring a creature to have had an ability for any minimum duration before it can use it during blocking (CR 509.1).
Instants can be cast any time a player has priority, including during the declare attackers step or at the start of the declare blockers step, before blockers are actually declared (CR 509.1b). This makes it entirely legal to cast a spell in response to attacks that grants flying and then use that ability to block.
Example: Your opponent attacks with a 2/2 creature with flying. You control a 2/2 Grizzly Bears with no abilities. In response to the attack, you cast Leap (an instant that gives target creature flying until end of turn) on your Bears. When the declare blockers step begins, your Bears now have flying and can legally block the opponent's flying attacker.
This is a common and legitimate combat trick. The key rule is that the game checks a creature's characteristics — including keyword abilities like flying — only at the relevant decision point, which here is when you declare your blocker (CR 509.1, 702.9a).
Unofficial fan resource — not affiliated with or endorsed by Wizards of the Coast. Answers are AI-generated estimates grounded in the Comprehensive Rules and are not a substitute for an official judge. Verify anything match-critical.